【问题标题】:How to access value of nested dictionary with only subkey?如何仅使用子键访问嵌套字典的值?
【发布时间】:2017-05-05 11:00:10
【问题描述】:

我有以下嵌套字典:

{
  "category": "string",
  "top_bottom": {
    "count": 0,
    "data": [
      {
        "store_name": "string",
        "store_id": "string",
        "value": 0
      }
    ],
    "end_name": "string"
  }
}

我想获取键 store_name 的值。我该怎么做?

【问题讨论】:

    标签: python string dictionary itertools


    【解决方案1】:

    您总是需要知道到达那里的“完整路径”。因此,例如,如果您的字典名为 myDict,您将使用

    myDict["top_bottom"]["data"][0]["store_name"]
    

    如果您无法知道“完整路径”,最好为您的数据考虑不同的结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 2020-08-08
      • 1970-01-01
      相关资源
      最近更新 更多