'How to loop thru JSON list and save data in Django

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'],
            ...


Solution 1:[1]

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'],
            ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dreamer's redemption