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

      <legend id='KZmjW'><style id='KZmjW'><dir id='KZmjW'><q id='KZmjW'></q></dir></style></legend>

      <small id='KZmjW'></small><noframes id='KZmjW'>

        <tfoot id='KZmjW'></tfoot>

        将 JSON 转换为 YAML.将 JSON 解析为 YAML

        时间:2023-09-26

              <legend id='6ENKQ'><style id='6ENKQ'><dir id='6ENKQ'><q id='6ENKQ'></q></dir></style></legend>

              <small id='6ENKQ'></small><noframes id='6ENKQ'>

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

                  <tbody id='6ENKQ'></tbody>
                • <bdo id='6ENKQ'></bdo><ul id='6ENKQ'></ul>

                  本文介绍了将 JSON 转换为 YAML.将 JSON 解析为 YAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在处理配置文件,因此我需要将 JSON 转换为 YAML.例如我有这个 JSON 文件:

                  I'm working with configuration files so I need to convert JSON to YAML. For example I have this JSON file:

                  {
                    "foo": "bar",
                    "baz": [ "qux","quxx"],
                    "corge": null,
                    "grault": 1,
                    "garply": true,
                    "waldo": "false",
                    "fred": "undefined",
                    "emptyArray": [],
                    "emptyObject": {},
                    "emptyString": ""
                  }
                  

                  结果应该是 YAML:

                  The result should be YAML:

                  foo: "bar"
                  baz: 
                    - "qux"
                    - "quxx"
                  corge: null
                  grault: 1
                  garply: true
                  waldo: "false"
                  fred: "undefined"
                  emptyArray: []
                  emptyObject: {}
                  emptyString: ""
                  

                  你能帮帮我吗?

                  推荐答案

                  如果您需要将 JSONobject 转换为 yaml(字符串).你需要.首先获取json字符串,然后map,之后就可以转换成yaml了.代码如下:

                  If you need convert JSONobject to yaml (string). you need. Firstly get json string, then map, after that you can convert to yaml. Here the code:

                    // this is your json object
                    JSONObject jsonobject = new JSONObject(map);
                    // get json string
                    String prettyJSONString = jsonobject.toString(4);
                    // mapping
                    Map<String,Object> map = (Map<String, Object>) yaml.load(prettyJSONString);
                    // convert to yaml string (yaml formatted string)
                    String output = yaml.dump(map2);
                  

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

                  上一篇:如何在 Java 中将 YAML 转换为 JSON? 下一篇:如何从 OpenAPI 3.0 yaml 文件生成 JSON 示例?

                  相关文章

                  最新文章

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

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

                    <small id='Qft4e'></small><noframes id='Qft4e'>