2012-03-10 75 views
4

所有节点我有一个YAML文件看起来像这样:获取下YAML路径

Main: 
    topofhouse: 
    x: 276.4375 
    y: 71.0 
    z: -60.5 
    yaw: -290.7768 
    pitch: 35.400017 
    2ndfloor: 
    x: 276.5 
    y: 67.0 
    z: -60.5 
    yaw: -8.626648 
    pitch: 16.199997 
    home: 
    x: 276.5 
    y: 63.0 
    z: -60.5 
    yaw: -18.976715 
    pitch: -32.850002 

有没有办法让Main下的所有节点?

回答

5

要获得包含在Main节点ID:

file.getConfigurationSection("Main").getKeys(false); 

输出:

Set["topofhouse", "2ndfloor", "home"] 

ConfigurationSection.getConfigurationSection(String path)的方法用于得到在其上操作的路径。

ConfigurationSection.getKeys(boolean deep)方法将使您获取当前路径中的所有节点ID作为Set<String>。 当deep设置为true时,它也会得到子节点和子节点中的所有节点,但它们之间的所有关系都将丢失。