Python获取深层json值

时间
  {
  "export": {
    "version": "3.4",
    "date": "2018-08-09T13:19:46Z",
    "groups": [
      {
        "name": "Templates"
      }
    ],
    "templates": [
      {
        "template": "Template OS",
        "name": "Template OS",
        "description": "",
        "groups": [
          {
            "name": "Datawhatiwant"
          }
        ],

这是 JSON 代码的相关部分,我想要值datawhatiwant但是,如果我使用print json_data["export"],则会出现此错误:TypeError: string indices must be integers那么我怎样才能获得datawhatiwan呢?

史蒂夫·阿彻

你需要先解码json

import json

print(json.loads(json_data)["export"])

应该工作得更好,我想。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章