Skip to content
Advertisement

string indices must be integers json

i have a json data https://steamcommunity.com/id/RednelssGames/inventory/json/730/2 need get names of all the items

r = requests.get('https://steamcommunity.com/id/RednelssGames/inventory/json/730/2')
if r.json()['success'] == True:
     for rows in r.json()['rgDescriptions']:
         print(rows['market_hash_name'])

getting error string indices must be integers

Advertisement

Answer

Change the for-loop as follows:

                for rows in r.json()['rgDescriptions'].values():
                    print(rows['market_hash_name'])

By iterating over a dictionary like you did, you get the keys and not the values (rows). If you want to iterate over the values, you have to iterate over the return value of dict.values().

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement