python-3.x - Python - 查找具有匹配值的对象
问题描述
我从如下所示的 API 中检索了 JSON:
"entries": [
{
"cuid": "1234",
"name": "23423423",
"id": "5432",
},
{
"cuid": "12234",
"name": "123124",
"id": "5432",
},
我正在尝试遍历一个单独的名称列表并从匹配的对象中检索相应的 ID。
我使用json.loads将 JSON 存储在users_dict
我试图从中检索值的位置。
本质上,假设我有 name = "23423423" ,我如何在 users_dict 中找到具有该名称的对象并从中检索 "5432" 的 id。
我怎样才能完成这项任务?
解决方案
以下是我使用 CSV 作为列表的解决方案:
with open('test.csv') as f:
reader = csv.reader(f)
for row in reader:
user = (' '.join(row))
for i , val in enumerate(users_dict):
if (val["name"] == user):
deletion_list.append(val["id"])
推荐阅读
- java - 注释和异常
- html - 容器在我的 Vue Swiper 中没有内联
- delphi - E2555 无法捕获符号“Self”
- kubernetes - GKE 集群的权限
- regex - 无法在 perl6 中编写语法来解析带有特殊字符的行
- kubernetes - Istio mTLS 中的 TLS 版本和密码
- javascript - 导出前的 Ag-grid 角度格式数据
- vba - VBA 代码使 PPT 应用程序崩溃 - 原因不明
- google-app-engine - App Engine cron 作业未运行 - 标准环境 - Java
- jpa - JPA like-query,考虑语言环境