你如何在Java中实际解析YAML中的值?

时间:2010-08-02 22:46:43

标签: java parsing yaml

我有一个YAML文件,我正在使用它作为一种配置文件。它就像这样,

tests:
    - category: some_category
      test:
          - name: hello
            key1: value1
            key2: value2

          - name: hithere
            key1: value1
            key2: value2

我想做这样的事情:

for all tests as test:
  print test.name + test.key1

我看过JYaml和SnakeYaml,但他们似乎只是从YAML映射到Java对象。 YAML不适合这个吗?有没有一种简单的方法来实现这一目标?我需要的是迭代并获取每个的值,就像DOM遍历一样。

1 个答案:

答案 0 :(得分:1)

好吧我明白了。我正在使用YamlBeans,它为此提供了方法:https://github.com/EsotericSoftware/yamlbeans

相关问题