【发布时间】:2019-05-30 11:54:29
【问题描述】:
我目前有一个输出各种天气数据的 JSON 文件。我可以在一定程度上细化我想要的信息,但需要进一步细化但无法做到。
我尝试根据位置选择它,例如 [1],我还尝试根据键访问数据,例如['weather'] 但我只能在 Python 抛出错误之前对其进行如此多的改进。
{'coord': {'lon': -1.98, 'lat': 50.72}, 'weather': [{'id': 803, 'main':
'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'base':
'stations', 'main': {'temp': 293.6, 'pressure': 1022, 'humidity': 64,
'temp_min': 292.15, 'temp_max': 294.82}, 'visibility': 10000, 'wind':
{'speed': 5.1, 'deg': 230}, 'clouds': {'all': 75}, 'dt': 1559214671,
'sys': {'type': 1, 'id': 1401, 'message': 0.0072, 'country': 'GB',
'sunrise': 1559188945, 'sunset': 1559246925}, 'timezone': 3600, 'id':
2640101, 'name': 'Poole', 'cod': 200}
上面的代码是我必须使用的 JSON 文件,我想提炼和提取例如 'weather' 中的 'main' 值,所以我想提取字符串 'Clouds' 但我已经尝试过像 dict['weather]['main'] 但它只是抛出一个错误。
寻求一些建议:D
【问题讨论】:
-
预期输出是什么?你能把它添加到问题中
标签: python json python-3.x