#๐Ÿ”’ why cant i retrive the data from this json file?

37 messages ยท Page 1 of 1 (latest)

serene pond
#

im trying to get this data from this part of the json but it doesnt want to

hidden oracleBOT
#

@serene pond

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

serene pond
#

this is what im doing

#

print(a['jsondata'])

#

im trying to get this part of the json file

#

{"localized_subtitle":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]

#

but when i do print(a['jsondata']['localized_subtitle]) it just gives me the error TypeError: string indices must be integers, not 'str'

#

why cant i retrive the data from this json file?

tidal mason
#

I'm assuming your Discord bot will be showing these updates correct?

#

You know Valorant has an official Discord and you can subscribe to be notified of updates?

serene pond
#

no its not for valorant

#

im just trying to get the json data

#

that i collected

#

but i cant

serene pond
#

no its not anything to do with riot

#

i gave up on trying on the valorant

pseudo herald
#

print(repr(a['jsondata']))
it's possible the jsondata is not actually a dictionary, but just a string, that needs to be parsed using the json module

#

the "null" should be a strong indicator for that, as "null" doesn't exist in python (null in json get converted to None in python if you parse it using the json module)

serene pond
#

ok ill check if out

#

so like this print(repr(a['jsondata']['my_data']))

pseudo herald
#

no

#

literally as I showed it

#

the repr() is just there to show you that you got a string

#

and not a dictionary

serene pond
#

and how would i get the dictionary?

pseudo herald
#

!e

some_data = '{"foo": [null,null,null]}'
print(some_data)
print(repr(some_data))
hidden oracleBOT
#

@pseudo herald :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | {"foo": [null,null,null]}
002 | '{"foo": [null,null,null]}'
pseudo herald
#

like I said: with the json module

#

data = json.loads(a['jsondata'])

#

probably

serene pond
#

ok

#

thx it worked

#

!close

hidden oracleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.