Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python读取JSON URL以创建有用的字典_Python_Json_Dictionary - Fatal编程技术网

如何使用Python读取JSON URL以创建有用的字典

如何使用Python读取JSON URL以创建有用的字典,python,json,dictionary,Python,Json,Dictionary,我使用的数据可以在这里找到- 我目前正在使用此代码读取数据,但结果对我来说是陌生的,我不确定如何使用它: import requests site='http://www.bom.gov.au/fwo/IDN60801/IDN60801.95896.json' r=requests.get(site) print r.json() 这输出了一个庞大的字典??我不确定如何检索,但我希望能够从这个JSON站点检索到的是第一个“air\u temp”值 我相信这并不难,我只是一个n00b 谢谢你

我使用的数据可以在这里找到-

我目前正在使用此代码读取数据,但结果对我来说是陌生的,我不确定如何使用它:

import requests

site='http://www.bom.gov.au/fwo/IDN60801/IDN60801.95896.json'
r=requests.get(site)

print r.json()
这输出了一个庞大的字典??我不确定如何检索,但我希望能够从这个JSON站点检索到的是第一个“air\u temp”值

我相信这并不难,我只是一个
n00b

谢谢你的帮助

以下是一些示例输出:


看看python

要提取所有温度:

>>> r=requests.get(site)
>>> data = r.json()
>>> allTemps = [item['air_temp'] for item in data['observations']['data']]
>>> print(allTemps)
[32.2, 32.4, 33.0, 36.6, 40.7, 41.2, 40.8, 39.8, 39.6, 40.6, 40.9, 40.4, 41.1, 40.5, 40.4, 41.2, 39.6, 40.6, 39.1, 39.1, 38.6, 38.6, 33.6, 31.5, 29.1, 26.6, 25.7, 23.5, 22.4, 20.2, 19.8, 17.2, 17.2, 17.3, 17.7, 18.1, 18.4, 18.8, 18.9, 20.2, 20.6, 21.0, 20.4, 21.7, 22.3, 23.5, 23.5, 23.0, 24.7, 27.9, 28.9, 28.1, 33.2, 34.2, 35.9, 36.7, 37.4, 37.5, 37.7, 37.5, 37.6, 37.7, 38.0, 37.1, 36.5, 36.6, 35.7, 34.9, 34.3, 32.9, 31.6, 30.1, 28.7, 27.1, 25.6, 24.3, 22.7, 21.2, 19.5, 17.9, 16.9, 17.7, 17.9, 18.0, 18.6, 18.9, 20.1, 20.1, 20.2, 20.9, 21.5, 21.0, 21.5, 22.6, 25.1, 24.5, 24.9, 26.1, 27.2, 29.8, 30.3, 32.1, 33.3, 34.3, 35.0, 35.4, 35.7, 36.0, 35.9, 35.6, 35.0, 35.7, 34.7, 35.0, 34.5, 34.1, 33.6, 32.9, 32.2, 31.3, 29.3, 27.1, 25.3, 23.6, 22.7, 20.9, 19.6, 18.4, 18.2, 18.1, 17.7, 18.2, 18.1, 18.9, 19.6, 19.8, 20.8, 21.7, 22.0, 22.6, 22.7, 23.7, 24.5, 24.2, 25.5, 26.8, 28.6, 29.3, 30.8, 31.8, 33.3, 34.1, 34.4]
只是第一个温度:

>>> firstTemp = data['observations']['data'][0]['air_temp']
>>> print(firstTemp)
32.2
看看python

要提取所有温度:

>>> r=requests.get(site)
>>> data = r.json()
>>> allTemps = [item['air_temp'] for item in data['observations']['data']]
>>> print(allTemps)
[32.2, 32.4, 33.0, 36.6, 40.7, 41.2, 40.8, 39.8, 39.6, 40.6, 40.9, 40.4, 41.1, 40.5, 40.4, 41.2, 39.6, 40.6, 39.1, 39.1, 38.6, 38.6, 33.6, 31.5, 29.1, 26.6, 25.7, 23.5, 22.4, 20.2, 19.8, 17.2, 17.2, 17.3, 17.7, 18.1, 18.4, 18.8, 18.9, 20.2, 20.6, 21.0, 20.4, 21.7, 22.3, 23.5, 23.5, 23.0, 24.7, 27.9, 28.9, 28.1, 33.2, 34.2, 35.9, 36.7, 37.4, 37.5, 37.7, 37.5, 37.6, 37.7, 38.0, 37.1, 36.5, 36.6, 35.7, 34.9, 34.3, 32.9, 31.6, 30.1, 28.7, 27.1, 25.6, 24.3, 22.7, 21.2, 19.5, 17.9, 16.9, 17.7, 17.9, 18.0, 18.6, 18.9, 20.1, 20.1, 20.2, 20.9, 21.5, 21.0, 21.5, 22.6, 25.1, 24.5, 24.9, 26.1, 27.2, 29.8, 30.3, 32.1, 33.3, 34.3, 35.0, 35.4, 35.7, 36.0, 35.9, 35.6, 35.0, 35.7, 34.7, 35.0, 34.5, 34.1, 33.6, 32.9, 32.2, 31.3, 29.3, 27.1, 25.3, 23.6, 22.7, 20.9, 19.6, 18.4, 18.2, 18.1, 17.7, 18.2, 18.1, 18.9, 19.6, 19.8, 20.8, 21.7, 22.0, 22.6, 22.7, 23.7, 24.5, 24.2, 25.5, 26.8, 28.6, 29.3, 30.8, 31.8, 33.3, 34.1, 34.4]
只是第一个温度:

>>> firstTemp = data['observations']['data'][0]['air_temp']
>>> print(firstTemp)
32.2