我有一个如下所示的 json:
[
{
"status":"passed",
"elements":[{"name":"foo"},{"name":"bar"}]
},
{
"status":"failed",
"elements":[{"name":"foo1"},{"name":"bar1"}]
}
]
我正在尝试迭代元素数组:
for a in json['elements']:
print a['name']
我收到此错误:
TypeError: list indices must be integers, not str
我的Python实在是太糟糕了。谢谢
最佳答案
试试这个:
for a in json:
for b in a['elements']:
print b['name']
关于Python 循环嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41383215/