• <bdo id='UgyHP'></bdo><ul id='UgyHP'></ul>

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

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

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

      2. 将 json 转储到 yaml

        时间:2023-09-12
      3. <tfoot id='6s70G'></tfoot>
          <tbody id='6s70G'></tbody>

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

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

                  <legend id='6s70G'><style id='6s70G'><dir id='6s70G'><q id='6s70G'></q></dir></style></legend>
                  本文介绍了将 json 转储到 yaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 .json 文件(将其命名为 meta.json),如下所示:

                  I got a .json file (named it meta.json) like this:

                  {
                      "main": {
                          "title": "今日は雨が降って",
                          "description": "今日は雨が降って"
                      }
                  }
                  

                  我想将其转换为 .yaml 文件(将其命名为 meta.yaml),例如:

                  I would like to convert it to a .yaml file (named it meta.yaml) like :

                  title: "今日は雨が降って"
                  description: "今日は雨が降って"
                  

                  我所做的是:

                  import simplejson as json
                  import pyyaml
                  
                  f = open('meta.json', 'r')
                  jsonData = json.load(f)
                  f.close()
                  
                  ff = open('meta.yaml', 'w+')
                  yamlData = {'title':'', 'description':''}
                  yamlData['title'] = jsonData['main']['title']
                  yamlData['description'] = jsonData['main']['description']
                  yaml.dump(yamlData, ff)
                  # So you can  see that what I need is the value of meta.json     
                  

                  但遗憾的是,我得到的是以下内容:

                  But sadly, what I got is following:

                  {description: "u4ECAu65E5u306Fu96E8u304Cu964Du3063u3066", title: "u4ECAu65E5
                  u306Fu96E8u304Cu964Du3063"}
                  

                  为什么?

                  推荐答案

                  pyyaml.dump() 有 "allow_unicode" 选项,默认为 None,输出中的所有非 ASCII 字符都被转义.如果 allow_unicode=True 则写入原始 unicode 字符串.

                  pyyaml.dump() has "allow_unicode" option, it's default is None, all non-ASCII characters in the output are escaped. If allow_unicode=True write raw unicode strings.

                  yaml.dump(data, ff, allow_unicode=True)
                  

                  奖金

                  json.dump(data, outfile, ensure_ascii=False)
                  

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

                  上一篇:在 app.yaml 中定义路由与在 AppEngine 中的 WSGIAppli 下一篇:我可以加速 YAML 吗?

                  相关文章

                  最新文章

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

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

                • <small id='IvhAJ'></small><noframes id='IvhAJ'>

                        <bdo id='IvhAJ'></bdo><ul id='IvhAJ'></ul>
                      <tfoot id='IvhAJ'></tfoot>