I have the following json (I've stripped a lot of the data out for simplicity):
{u'_links': [{u'uri': u'http://url/polling/v1/c1b1a360-1c69-49e0-9114-f02e3697e3ea', u'rel': u'header', u'methods': [u'GET', u'POST', u'PUT', u'OPTIONS']}, {u'uri': u'http://url/polling/v1/c1b1a360-1c69-49e0-9114-f02e3697e3ea/stores', u'rel': u'self', u'methods': [u'GET', u'PUT', u'POST', u'DELETE', u'OPTIONS']}], u'data': [{u'status': u'C2001', u'stackTrace': None, u'receivedIdx': 53713, u'description': u'Staged', u'timeChanged': u'2017-07-12T07:00:11.949-0400', u'storeNbr': u'1280', u'_links': [{u'uri': u'http://url.com/polling/v1/c1b1a360-1c69-49e0-9114-f02e3697e3ea/stores/1280', u'rel': u'self', u'methods': [u'GET', u'POST', u'DELETE', u'OPTIONS']}
I'm trying to get the "timeChanged" and "description" fields out of it.
data = json.loads(result.read())
for status in data:
print "[",status['timeChanged'],"]", status['description']
results in:
TypeError: string indices must be integers
What am I doing wrong?
Any help would be appreciated
dictrepresentation.print datais the string representation of adict, which is what randomir is trying to tell you. In other words,datais adict(which makes sense because you are deserializing a JSON object when you calljson.loads.)