<tfoot id='2oZyV'></tfoot>

      <bdo id='2oZyV'></bdo><ul id='2oZyV'></ul>

      <i id='2oZyV'><tr id='2oZyV'><dt id='2oZyV'><q id='2oZyV'><span id='2oZyV'><b id='2oZyV'><form id='2oZyV'><ins id='2oZyV'></ins><ul id='2oZyV'></ul><sub id='2oZyV'></sub></form><legend id='2oZyV'></legend><bdo id='2oZyV'><pre id='2oZyV'><center id='2oZyV'></center></pre></bdo></b><th id='2oZyV'></th></span></q></dt></tr></i><div id='2oZyV'><tfoot id='2oZyV'></tfoot><dl id='2oZyV'><fieldset id='2oZyV'></fieldset></dl></div>
    1. <legend id='2oZyV'><style id='2oZyV'><dir id='2oZyV'><q id='2oZyV'></q></dir></style></legend>

      <small id='2oZyV'></small><noframes id='2oZyV'>

    2. 解析 YAML 文件

      时间:2023-09-26
      <i id='58A4M'><tr id='58A4M'><dt id='58A4M'><q id='58A4M'><span id='58A4M'><b id='58A4M'><form id='58A4M'><ins id='58A4M'></ins><ul id='58A4M'></ul><sub id='58A4M'></sub></form><legend id='58A4M'></legend><bdo id='58A4M'><pre id='58A4M'><center id='58A4M'></center></pre></bdo></b><th id='58A4M'></th></span></q></dt></tr></i><div id='58A4M'><tfoot id='58A4M'></tfoot><dl id='58A4M'><fieldset id='58A4M'></fieldset></dl></div>
        <legend id='58A4M'><style id='58A4M'><dir id='58A4M'><q id='58A4M'></q></dir></style></legend>
          • <small id='58A4M'></small><noframes id='58A4M'>

            1. <tfoot id='58A4M'></tfoot>

                <tbody id='58A4M'></tbody>
                <bdo id='58A4M'></bdo><ul id='58A4M'></ul>
              • 本文介绍了解析 YAML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                这是我第一次使用 YAML 文件,所以我首先想到的是找到任何可以帮助我解析文件的库.

                This is the first time I am working with YAML files, so the first think I looked at was to find any library that could help me to parse the file.

                我找到了两个库,YamlBean 和 SnakeYAML.我不确定我要使用哪一个.

                I have found two libraries, YamlBean and SnakeYAML. I am not sure which one that I am going to use.

                这是我尝试解析的文件示例:

                Here is an example of the file that I am trying to parse:

                users:
                  user1:
                    groups:
                    - Premium
                  user2:
                    groups:
                    - Mod
                  user3:
                    groups:
                    - default
                groups:
                  Mod:
                    permissions:
                      test: true
                    inheritance:
                    - Premium
                  default:
                    permissions:
                      test.test: true
                    inheritance:
                    - Mod
                  Admin:
                    permissions:
                      test.test.test: true
                    inheritance:
                    - Mod
                

                文件会动态变化,所以我不知道该文件将包含多少用户或组.

                The file will change dynamical so I don't know how many users or groups the file would contain.

                我想从中获取的信息是用户名和组,如下所示:

                The information I would like to fetch from this is the user name and the group like this:

                user1 Premium
                user2 Mod
                user3 default
                

                从组中只有组名,如下所示:

                And from the groups only the group names, like this:

                Mod
                default
                Admin
                

                谁能帮我从这里开始?什么是最好的图书馆?YamlBean 还是 SnakeYAML?

                Anyone could get me started here? And what is the best library to use for this? YamlBean or SnakeYAML?

                我想,我需要将信息保存在我可以轻松迭代的内容中.

                I guess, I need to save the information in something that I easily could iterate over.

                推荐答案

                我最终使用了 SnakeYaml 并制作了一些拆分字符串来解决我的问题.

                I ended up using SnakeYaml and made some split strings to solve my issue.

                将yaml文件加载到Object中,然后加载到Map中,然后将Map中的结果拆分为String[] 然后在 for 循环中,我从 String[] 中读出名称.我对组也做了同样的事情.

                Loaded the yaml file to Object and then into a Map, then split the result from the Map into String[] and then in a for loop I read out the name from the String[]. I did the same with groups.

                我知道有更好的解决方案,但这对于这个项目来说已经足够了.

                I know that there is better solutions out there but this is good enough for this project.

                感谢大家的回复.

                这篇关于解析 YAML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何使用 JDBC 连接 XAMPP MySQL 本地数据库? 下一篇:如何在 Java 中将 YAML 转换为 JSON?

                相关文章

                最新文章

              • <i id='JqVba'><tr id='JqVba'><dt id='JqVba'><q id='JqVba'><span id='JqVba'><b id='JqVba'><form id='JqVba'><ins id='JqVba'></ins><ul id='JqVba'></ul><sub id='JqVba'></sub></form><legend id='JqVba'></legend><bdo id='JqVba'><pre id='JqVba'><center id='JqVba'></center></pre></bdo></b><th id='JqVba'></th></span></q></dt></tr></i><div id='JqVba'><tfoot id='JqVba'></tfoot><dl id='JqVba'><fieldset id='JqVba'></fieldset></dl></div>
              • <small id='JqVba'></small><noframes id='JqVba'>

                    <bdo id='JqVba'></bdo><ul id='JqVba'></ul>

                1. <tfoot id='JqVba'></tfoot>
                    <legend id='JqVba'><style id='JqVba'><dir id='JqVba'><q id='JqVba'></q></dir></style></legend>