用Python读取深度嵌套的Json对象

用Python读取深度嵌套的Json对象,python,json,Python,Json,我想读取深度嵌套的Json对象的值。我对达到温度值感兴趣 { "weatherChannel": [ { "week": { "location": [ { "info": [ {

我想读取深度嵌套的Json对象的值。我对达到
温度值感兴趣

{
    "weatherChannel": [
       {
           "week": {  
                "location": [
                    {
                        "info": [ 
                            {
                                "temperature": 5
                            }
                         ]
                     }
                 ]
            } 
        }
     ]
 }
我可以通过以下操作到达
位置
信息:
weatherChannel['week']['location']


任何关于如何实现这一目标的建议都将不胜感激。

weatherChannel包含一个列表,因此将
weatherChannel[0][“周”][“位置”]


这提供了你所需要的。您需要了解,
[]
表示列表,您可以通过列表元素的位置(第一个位置是0,而不是1)访问列表元素。而
{}
表示字典,其中包含成对的
键:值
,例如
“温度”:5
,您可以通过它们的键访问这些值。

什么是“无法”呢
weatherChannel['week']['location']
是一个数组,但事实上,你已经做到了这一点,这表明你知道如何从数组中提取对象。是的,jonrsharpe一针见血,你在这里混合了内容-因此你的weatherChannel对象由一个列表组成,其中第一个元素包含一个字典,其中的“week”是一个键,然后有一个子字典,其中“location”作为键,然后在这个子字典中,它是另一个列表,包含一个字典,其中“info”键返回一个集合-这个列表的第一个元素是另一个字典,包含“temperature”键。您需要类似于
weatherChannel[0][“week”][“location”][0][“info”][0][“temperature”]
的内容。谢谢你们的评论。是的,这是我这边的疏忽。感谢你的解释
d = {
     "weatherChannel": [
        {
            "week": {  
                 "location": [
                     {
                         "info": [ 
                             {
                                 "temperature": 5
                             }
                          ]
                      }
                  ]
             } 
         }
      ]
  }

d["weatherChannel"][0]["week"]["location"][0]["info"][0]["temperature"]