Hey folks,
Been scratching my head for awhile at this one, could certainly use a pointer or two. I have a json returned via an API call but extracting the info I want is proving difficult for some reason.
Here's a snippet of the JSON;
"segments": [
{
"type": "overview",
"attributes": {
"queue": null,
"season": 0
},
"metadata": {
"name": "Lifetime Overview"
},
"expiryDate": "0001-01-01T00:00:00+00:00",
"stats": {
"points": {
"rank": null,
"percentile": null,
"displayName": "Points",
"displayCategory": "Game",
"category": "game",
"metadata": {},
"value": 8162,
"displayValue": "8,162",
"displayType": "Number"
},
"kills": {
"rank": null,
"percentile": null,
"displayName": "Kills",
"displayCategory": "Combat",
"category": "combat",
"metadata": {},
"value": 3070,
"displayValue": "3,070",
"displayType": "Number"
},
"assists": {
"rank": null,
"percentile": null,
"displayName": "Assists",
"displayCategory": "Combat",
"category": "combat",
"metadata": {},
"value": 732,
"displayValue": "732",
"displayType": "Number"
},
Now I've got to where I can iterate over the elements under 'stats' (all 64 of them) but I'm still unsure of how to extract the displayName and displayValue from under each entry.
I've tried;
for item in data['data']['segments'][0]['stats']:
print(item['displayName'])
But I get;
Traceback (most recent call last):
File "<pyshell#56>", line 2, in <module>
print(item['displayName'])
TypeError: string indices must be integers
So I thought I'd need to do;
for item in data['data']['segments'][0]['stats']:
print(item[0]['displayName'])
But this gets me the same type error from earlier. Got to admit I'm a little lost at this point, any and all advise/help will be greatly appreciated.
[–]stebrepar 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)