【发布时间】:2020-10-30 22:00:18
【问题描述】:
我正在尝试遍历下面的 json,但我只得到第一项。我知道指定键 [1] 是原因。我该如何克服这个问题?
for i in testing['Items']:
MyFunc = testing['Items'][1]['Id']
Containers = UrlFormater(MyFunc)
JSON:
{'Items': [{'Id': 'Test1', 'Type': 'Address', 'Text': '',
'Highlight': '', 'Description': ''}, {'Id': 'Test2', 'Type':
'Address', 'Text': '', 'Highlight': '', 'Description': ''}
}]}
【问题讨论】:
-
MyFunc = i['Id']。这就是i在for i in ...中的用途。 -
如果不使用
i,循环还有什么意义?
标签: python json loops for-loop