I'm relatively new to this so please excuse me if I'm missing something very obvious :)
I'm trying to print code, and value of the attached Json file.
for example
for item in dataxchjs['data']:
print(item)
works perfectly, and prints me AED as the first value
But
for item in dataxchjs['data']:
print(item["code"], item["value"])
returns the error code
, line 47, in <module>
print(item["code"], item["value"])
TypeError: string indices must be integers
What am I missing?
json file:
{
"meta": {
"last_updated_at": "2022-04-04T23:59:59Z"
},
"data": {
"AED": {
"code": "AED",
"value": 3.67321
},
"AFN": {
"code": "AFN",
"value": 89.00134
},
...
}
Thank you all very much
please don't dislike the post I really tried to understand the problem myself for a while now
for key, item in dataxchjs['data'].items()orfor item in dataxchjs['data'].values()datais a dict. when you iterate over dict, you iterate over dict keys. In your case - strAED,AFN, etc.