This is my JSON
{"sites":[{"site_id":1234,..,..}, {"site_id":5678,..,..}]}
I'm trying to loop through it using:
for site_id in account['sites']['site_id']:
print(site_id)
Which yields:
list indices must be integers, not str
account['sites']
is a list of dictionaries, iterate over it and get the value by site_id
key:
for site in account['sites']:
print site['site_id']
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.