我有一个看起来像这样的json:

[
   {
      "status":"passed",
      "elements":[{"name":"foo"},{"name":"bar"}]
   },
   {
      "status":"failed",
      "elements":[{"name":"foo1"},{"name":"bar1"}]
   }
]


我试图遍历elements数组:

for a in json['elements']:
   print a['name']


我收到此错误:


  TypeError:列表索引必须是整数,而不是str


我的python真的很糟糕。谢谢

最佳答案

尝试这个:

for a in json:
   for b in a['elements']:
       print b['name']

关于python - Python遍历嵌套数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41383215/

10-15 22:57
查看更多