简体   繁体   中英

Python iterating on JSON objects

Here's the code

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) 

Here's the output

alpine
a
l
p
i
n
e

here's what i want to happen

print(tag['tag'])
3.11

print(tag['creation_date'])
2020-01-18T01:19:37.187497623Z

You want this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM