有没有办法获取所有 YAML 密钥并为每个密钥执行不同的任务?

Is there a way to get all YAML keys and do a different task for each of them?

到目前为止我已经得到了这段代码

            Set<String> key = cfg.getKeys(false);

cfg = YAML 文件

我想做一些可以获取所有密钥然后我可以单独使用它们的东西

示例:

我有一个包含字符串 1、2、3、4 的 YAML 文件

例如,当我将它们悬停在游戏中时,它会显示文本“这是数字..”

您可以使用 Snake yaml.

在你的项目中添加依赖

<dependency>
  <groupId>org.yaml</groupId>
  <artifactId>snakeyaml</artifactId>
  <version>1.29</version>
  <type>bundle</type>
</dependency>

传递yaml文件路径,获取所有key

InputStream inputStream = new FileInputStream(new File("<your_yaml_file_path>"));

Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(inputStream);
Set<String> keys = data.keySet();