我有以下数据来自JSON:
EVENT = {
'eventid': '11828346',
'acknowledges': [{'alias': 'user1', 'name': 'userXYZ'}],
'objectid': '25946',
'clock': '1444051689',
'object': '0',
'acknowledged': '0',
'value': '0'
}
所以,要从这本词典中得到我想要的东西:
for t in EVENT:
TRIGGERID = t['objectid']
HOUR = t['clock']
ACK = t['acknowledged']
这部分没问题,但是如何从内部字典中获取数据?
[{'alias': 'user1', 'name': 'userXYZ'}]
答案 0 :(得分:4)
字典存储在列表中(出于某些奇怪的原因),所以你可以做
inner_dict = EVENT['acknowledged'][0]
获取内部字典,然后从中选择
inner_dict['alias']