python: read json and loop dictionary

后端 未结 2 1382
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 10:13

I\'m learning python and i loop like this the json converted to dictionary: it works but is this the correct method? Thank you :)

import json

output_file =          


        
2条回答
  •  爱一瞬间的悲伤
    2020-11-30 10:49

    json_data = json.loads(url)

    If list is there, then iterate:

     for majorkey, subdict in json_data.iteritems():
       for one_majorkey in subdict:
        for subkey, value in one_majorkey.iteritems():
            for each_subkey, valu_U in value.iteritems():
                for each_sub_subkey, value_Q in valu_U.iteritems():
                    for each_sub_sub_subkey, value_num in value_Q.iteritems():
                        print each_sub_sub_subkey, value_num
    

提交回复
热议问题