You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从requests.get返回的JSON数据中提取adblue_level_percentage的value值

问题:提取API返回数据中指定字段的value值

我使用requests.get发起API请求后,遇到了数据取值的问题。示例代码如下:

response = requests.get('https://api-prd.dev/analytics/api/properties?filter[a.id]=' + aid, headers=headers)
request = response.json()
print(":0:>>>>> ", request['data'][0])

打印结果为:

:0:>>>>>  {'type': 'id-snapshot-property', 'id': 'adblue_level_percentage', 'attributes': {'updateDate': '2022-10-07T13:39:32Z', 'value': '0'}}

请问如何提取adblue_level_percentage对应的value值(即0)?


解答:

通过嵌套字典的键路径直接取值即可,代码如下:

request['data'][0]['attributes']['value']

内容的提问来源于stack exchange,提问作者pyrazs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 17:15:48