Get all nodes under YAML path

↘锁芯ラ 提交于 2019-12-30 10:10:13

问题


I have a YAML file that looks like this:

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

Is there a way to get all nodes under Main?


回答1:


To get the node IDs contained in Main:

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

Output:

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

The ConfigurationSection.getConfigurationSection(String path) method is used to get the path on which to operate.

The ConfigurationSection.getKeys(boolean deep) method will get you all node IDs within the current path as a Set<String>. When deep is set to true, it will get all the nodes in the children and subchildren too, however, all relations between them will be lost.



来源:https://stackoverflow.com/questions/9648549/get-all-nodes-under-yaml-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!