python - 数组循环内的字典
问题描述
给定一个包含以下数据的 json 文件:
[
{
"activityId": "Task_5.1.1",
"activityInstanceId": "Task_5.1.1:8c42f564-cdbe-11ea-8be8-00155d891509",
"errorMessage": null,
"errorDetails": null,
"executionId": "8c42ce53-cdbe-11ea-8be8-00155d891509",
"id": "8c431c75-cdbe-11ea-8be8-00155d891509",
"lockExpirationTime": null,
"processDefinitionId": "Process_5.1.1:1:d1c02af8-cdb8-11ea-8be8-00155d891509",
"processDefinitionKey": "Process_5.1.1",
"processInstanceId": "8c42802b-cdbe-11ea-8be8-00155d891509",
"retries": null,
"suspended": false,
"workerId": null,
"topicName": "AppointIM",
"tenantId": null,
"priority": 0,
"businessKey": "57a4c7e9-fd9f-4d71-a39d-7bd8e112a39a"
},
{
"activityId": "Task_5.1.1",
"activityInstanceId": "Task_5.1.1:fcad6582-cdb8-11ea-8be8-00155d891509",
"errorMessage": null,
"errorDetails": null,
"executionId": "fcad6581-cdb8-11ea-8be8-00155d891509",
"id": "fcad6583-cdb8-11ea-8be8-00155d891509",
"lockExpirationTime": null,
"processDefinitionId": "Process_5.1.1:1:d1c02af8-cdb8-11ea-8be8-00155d891509",
"processDefinitionKey": "Process_5.1.1",
"processInstanceId": "fcacf049-cdb8-11ea-8be8-00155d891509",
"retries": null,
"suspended": false,
"workerId": null,
"topicName": "AppointIM",
"tenantId": null,
"priority": 0,
"businessKey": "f254eb9e-93a5-48e0-8a8e-a95c9fd17ab3"
}
]
我试图只保存 businessKey 等于某个值的字典。然后这将显示在模板中。
我可以使用以下方式访问每个项目:items_display = list_task['tasks'][0]
但有时可能多达 1000 套或少至 0 套。
我需要一种方法,首先搜索具有所需值的所有字典:然后丢弃剩余部分,或者将找到的项目保存到可以在模板中访问的新字典中。
我尝试不同的方法等已经失败了超过 4 个小时:
我可以通过使用上面的索引来获取键:值等,但需要一种方法来遍历所有可能的索引数量。
解决方案
推荐阅读
- reactjs - React Bootstrap导航栏:元素类型无效:需要字符串或类/函数
- reactjs - React Native: how to set different state values from multiple identical child components
- python - How to obtain pagination for the Mongo Aggregate
- python - factoryboy override attribute of lazy_attribute
- vba - 5974 Word Runtime Error 尝试连续使用宏后
- java - How to do a Mongo aggregation query in Spring Data?
- c# - 寻找使这段代码通用的方法
- python - 将直方图的图像转换为直方图值?
- r - Why my script taking more time using data.table compared to data.frame (example given)?
- cocoa - 在 Catalina 中,`orderFront:` 使应用程序成为活动应用程序;我该如何防止这种情况?