【发布时间】:2017-08-22 09:14:37
【问题描述】:
这是对我之前提出的问题的更具体的跟进。基本上,我试图从处理 GET 请求后收到的 JSON 文本块中提取特定数据。在限制为项目之后(通过使用 dict.items() 方法),我得到了以下 JSON 数据(有很多,但这只是一个示例):
[('response',
{'count': 84,
'users': [{'location_id': 123456,
'acx_audit': None,
'flash_backup_url': u'',
'flash_backup_url_secure': u'',
'flash_click_variable': None,
'folder': None,
'format': u'url-json',
'height': 1,
'id': 36619222,
'is_prohibited': False,},
{'location_id': 5556667,
'acx_audit': None,
'flash_backup_url': u'',
'flash_backup_url_secure': u'',
'flash_click_variable': None,
'folder': None,
'format': u'url-json',
'height': 1,
'id': 4567777,
'is_prohibited': False,}
我正在尝试提取的数据是这些对象中的每一个的“id”编号(不是“location_id”),并将所有这些编号收集到一个数组中。我有点挣扎,因为我不习惯使用像这样的大型 JSON 数据结构,其中字典和数组相互嵌套。我是否还必须运行一个循环来完成此操作?
任何帮助将不胜感激,因为我现在被困住了。谢谢。
【问题讨论】:
标签: python arrays json python-2.7 dictionary