我有一个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?

有帮助吗?

解决方案

获取包含在 Main:

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

输出:

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

ConfigurationSection.getConfigurationSection(String path) 方法用于获取要操作的路径。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top