I am trying to retrieve the 'id' value : ad284hdnn.
I am getting the following error : TypeError: string indices must be integers
data = response.json()
print data
for key in data['result']:
print key['id']
Here is the json that is returned when print the data string.
{u'meta': {u'httpStatus': u'200 - OK', u'requestId': u'12345'}, u'result': {u'username': u'[email protected]', u'firstName': u'joe', u'lastName': u'bloggs', u'accountStatus': u'active', u'id': u'ad284hdnn'}}
data['result']
is a dictionary. Iterating over dict
means iterating over its keys. Therefore key
variable stores a string. That's why key['id']
raises TypeError: string indices must be integers
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With