6

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'test@test.com', u'firstName': u'joe', u'lastName': u'bloggs', u'accountStatus': u'active', u'id': u'ad284hdnn'}}
Martin
  • 197
  • 1
  • 4
  • 12

1 Answers1

9

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.

radzak
  • 2,986
  • 1
  • 18
  • 27