【发布时间】:2022-11-16 23:39:12
【问题描述】:
我在解析下面的 JSON Response Dict 对象以返回/打印“数据”值 (testing.test.com) 时遇到问题。请参阅下面的字典:
[{'_id': '~1742209152', 'id': '~1742209152', 'createdBy': 'test@test.com',
'createdAt': 1666089754558, '_type': 'case_artifact', 'dataType': 'domain', 'data':
'testing.test.com', 'startDate': 1666089754558, 'tlp': 2, 'pap': 2, 'tags':
['Domain'], 'ioc': True, 'sighted': True, 'message': '', 'reports': {}, 'stats': {},
'ignoreSimilarity': False}]
每当我运行以下代码以尝试解析数据时,都会显示错误“print(observables['data'])TypeError: list indices must be integers or slice, not str':
observables = json.dumps(response) #getting JSON response dict which works fine
print(observables) #printing is successful
print(observables['data']) #issue is here
我意识到错误提示我使用 int 而不是 string,但是当我尝试反转它时,它不起作用并向我发送了无数错误。有没有具体的方法来做到这一点?我对自己的脚本编写能力并不过分自信,因此请多多指教!
Ps - 作为旁注,这种交互是通过 API 和我的 python 文件发生的,但由于我只是在 JSON 响应返回解析方面遇到问题,我怀疑这是否有任何影响。
【问题讨论】:
标签: python json parsing scripting jsonresponse