r = {'is_claimed': 'True', 'rating': 3.5}
r = json.dumps(r)
file.write(str(r['rating']))
I am not able to access my data in the JSON. What am I doing wrong?
TypeError: string indices must be integers, not str
dictionaryjsonpythonpython-2.7
r = {'is_claimed': 'True', 'rating': 3.5}
r = json.dumps(r)
file.write(str(r['rating']))
I am not able to access my data in the JSON. What am I doing wrong?
TypeError: string indices must be integers, not str
Best Answer
json.dumps()
converts a dictionary tostr
object, not ajson(dict)
object! So you have to load yourstr
into adict
to use it by usingjson.loads()
methodSee
json.dumps()
as a save method andjson.loads()
as a retrieve method.This is the code sample which might help you understand it more: