I have difficulty indexing json in Python. I think it's a preliminary question

Asked 1 years ago, Updated 1 years ago, 39 views

When I asked around, I heard that you need to put json instead of string to index even if it's not an integer.

Is the variable match not json? ㅠ<

Json from the web.

response = requests.get( url, headers=headers)
print(response)
match = response.json()
print(match)
print(match["matches"]["matches"]["characterName"])

json python

2022-09-22 14:57

1 Answers

Try this.

# Convert the response to a string and use json.loads()
# I don't know if the type (response) is str, json, or response object...
match = json.loads(str(response))

# It'll probably come out.
print(match["matches"]["matches"]["characterName"])


2022-09-22 14:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.