Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从所有这些节点获取值?_Java_Plugins_Minecraft_Bukkit - Fatal编程技术网

Java 如何从所有这些节点获取值?

Java 如何从所有这些节点获取值?,java,plugins,minecraft,bukkit,Java,Plugins,Minecraft,Bukkit,要获取每个公司的实际名称值,您可以首先在companys部分中获取所有直接子项键(就像您已经做的那样),这样,如果以后向配置文件添加更多顶级部分,您就不必遍历这些部分 如果您确定每个公司都将有一个名称值分配给它,那么您可以简单地使用直接路径(现在我们已经有了每个公司部分的名称)和companys.get(key+“.name”),其中key是公司部分的名称(例如simpleco)公司是所有公司的ConfigurationSection,或者您可以创建一个新的ConfigurationSectio

要获取每个公司的实际名称值,您可以首先在
companys
部分中获取所有直接子项键(就像您已经做的那样),这样,如果以后向配置文件添加更多顶级部分,您就不必遍历这些部分

如果您确定每个公司都将有一个名称值分配给它,那么您可以简单地使用直接路径(现在我们已经有了每个公司部分的名称)和
companys.get(key+“.name”)
,其中
key
是公司部分的名称(例如
simpleco
)公司是所有公司的
ConfigurationSection
,或者您可以创建一个新的
ConfigurationSection
更深一层(每个公司一个),并通过调用
getValues(false)检索键
“name”
的值。在该特定部分上获取(“name”)
。它看起来像这样:

    companies:
      simpleco:
        expenses: 3000
        revenue: 6000
        name: SimpleCo
      projectempireco:
        expenses: 5000
        revenue: 5500
        name: ProjectEmpireCo

getValues
应该可以@Bajal使用getValues()方法吗?很高兴我能帮上忙!如果答案解决了您的问题,您是否可以使用复选标记将其标记为“已接受”答案?这样每个人都知道你的问题已经解决了。谢谢
    companies:
      simpleco:
        expenses: 3000
        revenue: 6000
        name: SimpleCo
      projectempireco:
        expenses: 5000
        revenue: 5500
        name: ProjectEmpireCo
// Get config file, here called "fileConfig"
ConfigurationSection companies = fileConfig.getConfigurationSection("companies"); // The "companies" section of the config file

for (String companyKey : companies.getKeys(false)) { // For each company key in the set
    String name = (String) companies.get(companyKey + ".name"); // Either use the path to retrieve name value

    // OR

    ConfigurationSection companySection = companies.getConfigurationSection(companyKey); // Create a new section one level deeper
    name = (String) companySection.getValues(false).get("name"); // Retrieve name by getting value of key named "name"
}