我正在尝试检索“id”值:ad284hdnn。
我收到以下错误: TypeError: string indices must be integers
data = response.json()
print data
for key in data['result']:
print key['id']
这是打印数据字符串时返回的json。
{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']
是字典。迭代dict
意味着迭代它的键。因此key
变量存储一个字符串。这就是为什么key['id']
提出TypeError: string indices must be integers
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句