Python在JSON对象上迭代

Python在JSON对象上迭代,python,python-3.x,Python,Python 3.x,这是密码 images = { "alpine": [ { "tag": "3.11", "creation_date": "2020-01-18T01:19:37.187497623Z" } ] } for image in images: print(image) for tag

这是密码

images = {
    "alpine": [
        {
            "tag": "3.11",
            "creation_date": "2020-01-18T01:19:37.187497623Z"
        }
    ]
}

for image in images:
    print(image)
    for tag in image:
        print(tag) 

这是输出

alpine
a
l
p
i
n
e
这就是我想要发生的事情

print(tag['tag'])
3.11

print(tag['creation_date'])
2020-01-18T01:19:37.187497623Z
你想要这个:

>>> for key in images.keys():
...     for d in images[key]:
...         print(d['tag'], d['creation_date'])
... 
3.11 2020-01-18T01:19:37.187497623Z

您可能希望迭代
图像[“alpine”]
,而不是
图像
。如果要查看字典中的所有键和值,请使用
方法或
仅用于值。例如,
python For image[“alpine”]:For value in image.values():print(value)
您是否尝试过images.items()这不是“json对象”。JSON是一种基于文本的序列化格式。您正在使用python
dict
对象。