如何从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
相关产品推荐
相关产品推荐

