I try to get item from dict, which was decoded by json:
data = [ { 'a':'A', 'b':(2, 4), 'c':3 } ]
data_string = json.dumps(data)
decoded = json.loads(data_string)
decoded['c']
So it shows the next:
Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not str
I try to print the value of c on screen
So I try to see 3 after decoded[‘c’]
How can I do this ?
Thanks!
your data is a list containing a dictionary
you can use
decoded[0]['c']since the dictionary is the first element of the listanother possibility is that you should use
data = {u'a': u'A', u'c': 3, u'b': [2, 4]}(no square brackets)It really depends on whether you mean for data to be a list of dictionaries or just a dictionary