简体   繁体   中英

Iterate over json array with python 2.7

I want to iterate over json array that looks likes this.

[
{"key":"value"},
{"key2":"value2"},
{"key3":"value3"},
]

I have tried with json library but it's not possible to iterate over it. The index is not añways 0 but succesive

json_result = json.loads(json_var)

print(json_result[0])
print(json_result[0]["key"])

print(json_result[1])
print(json_result[1]["key1"])

comes with:

{"key":"value"}
value
{"key1":"value1"}
value1

So, I would like to get values without accessing their names. something like this:

for x in json_result:
 print(json_result[0][x])

Try this:

for i in list_json_var:
    for key in i:
        print(i[key])

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