【问题标题】:How do I get content of an inner JSON value in python?如何在 python 中获取内部 JSON 值的内容?
【发布时间】:2020-04-04 20:47:59
【问题描述】:

如何获取内部 JSON 值的内容? 比如我想获取Value2(2)的值-

{
  "JsonString": {
    "InnerJsonString": [
      {
        "Value1": "1",
        "Value2": "2",
        "Value3": "3",
        "Value4": "4"
      }
    ]
  }
}

【问题讨论】:

  • 如果data 是您的字典:data["JsonString"]["InnerJsonString"][0]["Value2"]
  • 这是 JSON 吗?或者这是dict?

标签: python arrays json python-3.x database


【解决方案1】:
import json    
with open("data.json", 'r') as jsonRaw:
    data = json.loads(jsonRaw.read())
    print(data["JsonString"]["InnerJsonString"][0]["Value2"]) # prints 2

【讨论】:

    猜你喜欢
    • 2012-08-06
    • 1970-01-01
    • 2012-01-29
    • 2015-10-31
    • 2014-10-08
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多