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

如何从API返回的JSON文件中打印指定嵌套键值对

提取JSON嵌套指定键值对

我调用API发送JSON格式请求,已成功将返回结果保存至文件并能打印完整内容,但希望仅打印该JSON文件中指定的嵌套键值对,而非全部内容。我尝试了以下代码来实现该需求:

nested_keys = ["eta", "arrT"]  
current_data = json_data

for keyValue in nested_keys:
    if keyValue in current_data:
        current_data = current_data[keyValue]
    else:
        print("Key not found in JSON data")
        break
else:
    print(current_data)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 04:04:52