【发布时间】:2020-06-08 11:20:35
【问题描述】:
我需要获取一个值,例如,如果动物是狗,那么我需要它的 id
{'findSomething': [{'Name': 'Andrew', 'id': '321Z4', 'animal': Dog }, {'Name': 'Andrew', 'id': '31Z45', 'animal': Cat }]}
【问题讨论】:
-
res[0] 知道它的第一行,但在我的情况下,我不确定动物会在第一行或其他,这就是为什么我会检查动物并获取相应的 id跨度>
-
Dog 是一个字符串(在这种情况下你错过了引号),还是一个对象?
-
res=your_dict.get('findSomething')print([x.get('id') for x in res if x.get('animal')=='Dog']),假设 Dog 是一个字符串 -
据我所知,JSON需要双引号...
-
你可以使用
json.load/loads将json加载到字典中,或者使用response.json()
标签: python json python-3.x python-requests python-requests-html