import requests
r = requests.get('https://REDACTED.zportal.nl/api/v3/appointments?user=~me&start=1542006900&end=1542009900&access_token=REDACTED')
print(r.json())
当我运行此代码时,我得到以下结果:
{
"response": {
"data": [
{
"locations": [
"018"
]
}
]
}
}
完整结果在这里:http://snippi.com/s/26v74yz
现在,我只想打印位置结果。如何筛选 json 结果,使其仅显示位置?
在Python中,JSON实际上就像字典一样工作,因此您可以使用方括号[]
来过滤它。见下文。
import requests
r = requests.get('https://REDACTED.zportal.nl/api/v3/appointments?user=~me&start=1542006900&end=1542009900&access_token=REDACTED')
locations = r.json()["response"]["data"][0]["locations"]
print(locations)