我不确定如何遍历这个特定结构,其中顶级键 A1 和 B6 是随机的。
我希望能够输出名称、x、y 和 yr
{
"A1": {
"msgs": ["Something there"],
"name": "Mary White",
"x": 132,
"y": 73,
"yr": 1978
},
"B6": {
"msgs": ["Something here"],
"name": "Joe Bloggs",
"x": 132,
"y": 73,
"yr": 2016
},
...
Run Code Online (Sandbox Code Playgroud)
使用以下内容加载我的 JSON
import json
with open('items.json') as data_file:
data = json.load(data_file)
Run Code Online (Sandbox Code Playgroud)
迭代.values():
import json
with open('data.json') as data_file:
data = json.load(data_file)
for v in data.values():
print(v['x'], v['y'], v['yr'])
Run Code Online (Sandbox Code Playgroud)