x = json.load(open('Download.json'))
for sub_dict in x['result']:
print('model', sub_dict["model"])
for entry in sub_dict['model']:
print(entry['downloadSize'])
Error:
print(entry['downloadSize'])
TypeError: string indices must be integers
I can not get the value of downloadurl
in any way. How to contact him correctly?
json structure attached in images
CodePudding user response:
x = json.load(open('Download.json'))
for sub_dict in x['result']:
print('model', sub_dict["model"])
print(sub_dict['model']['downloadSize'])
sub_dict['model'] is a dictionary not a list
so when you do for entry in sub_dict['model']
that is the same as
for key in sub_dict['model'].keys()
each "entry" in that iteration is just a string that is a key to the sub_dict['model'] dictionary