R
R
Roman Komyagin2020-08-13 00:42:32
Python
Roman Komyagin, 2020-08-13 00:42:32

How to get certain information from a .json file?

I need to get the amount of Wins i.e. wins
When I write:

r = response.json()
print(r['lifeTimeStats'])

I get:

[{'key': 'Top 5s', 'value': '1309'}, {'key': ' Top 3s', 'value': '737'}, {'key': 'Top 6s', 'value': '1014'}, {'key': 'Top 10', 'value': '729'} , {'key': 'Top 12s', 'value': '1899'}, {'key': 'Top 25s', 'value': '1175'}, {'key': 'Score', 'value ': '1,306,255'}, {'key': 'Matches Played', 'value': '11229'}, {'key': 'Wins', 'value': '1698'}, {'key': ' Win%', '



Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elvis, 2020-08-13
@BloomEe

for x in r['lifeTimeStats']:
    if x.get('key') == 'Wins':
        print(x.get('value'))
        break

D
Dr. Bacon, 2020-08-13
@bacon

Are you going to ask you to parse every json now? Basic work with lists and dictionaries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question