How to loop thru JSON list and save data in Django

Josh Ellen

I am trying loop thru JSON list data and save into the variable 'nfts'.

Exception Value: string indices must be integers

Traceback: nft_data_id = item['nfts'][item]['nft_data_id'],

JSON response: {"result":{"page_count":3041,"nfts":[{"nft_id":"#-#-#-#","nft_data_id":"#-#-#-#", ...

views.py Code:

def market_data(request):
    URL = '...'
    response = requests.get(URL).json()
    nfts = response['result']
    for item in nfts:
        nft_data = NFT_attributes(
            nft_data_id = item['nfts'][item]['nft_data_id'],
            ...
dreamer's redemption

you're iterating over an object instead of an array. kindly try below example

def market_data(request):
    URL = '...'
    response = requests.get(URL).json()
    nfts = response['result']['nfts']
    for nft in nfts:
        nft_data = NFT_attributes(
            nft_data_id = nft['nft_data_id'],
            ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related