你如何在Java中实际解析YAML中的值? [英] How do you actually parse values in YAML in Java?

查看:385
本文介绍了你如何在Java中实际解析YAML中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a YAML file that I'm using as sort of a config file. It ooks like this,

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遍历。

I have looked at JYaml and SnakeYaml but all they seem to do is map from YAML to Java objects. Is YAML not the right job for this? Is there a simple way to achieve this? all I need is to iterate through and get the values of each, kind of like a DOM traversal.

推荐答案

我认为它很好出。我正在使用YamlBeans,它提供了相应的方法: https://github.com/EsotericSoftware/yamlbeans

Well I figured it out. I am using YamlBeans, which provides methods for this: https://github.com/EsotericSoftware/yamlbeans

这篇关于你如何在Java中实际解析YAML中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆