Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fetch from json file (Python)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

json structure
json structure

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading