相关文章推荐
有情有义的大白菜  ·  python ...·  3 周前    · 
完美的馒头  ·  python QTreeWidget ...·  3 周前    · 
失眠的烤红薯  ·  python qt textBrowser ...·  2 周前    · 
帅气的领带  ·  【Pyspark ...·  2 天前    · 
近视的橙子  ·  python ...·  6 小时前    · 
光明磊落的毛巾  ·  针对 PHP ...·  7 月前    · 
聪明伶俐的大象  ·  c++11 - Android ...·  1 年前    · 
"icao": "LFPG", "observed": "2020-01-15T13:00:00.000Z", "raw_text": "LFPG 151300Z 21023G34KT CAVOK 12/05 Q1012 NOSIG", "station": { "name": "Charles de Gaulle International" "clouds": [ "code": "CAVOK", "text": "Clear skies" "flight_category": "VFR", "conditions": []

My current code is the following:

import requests
import json
hdr = my_header_here
req = requests.get("url", headers=hdr)
metarJSON = json.loads(req.text)

我所要做的是

print(metarJSON["data"][0]["wind"]["degrees"])

非常感谢你,从上周开始,我就是一个完全的python初学者了:)

3 个评论
print(metarJSON["data"][0]["wind"]["degrees"])应该做。这有什么问题吗?
It gives me TypeError: string indices must be integers
不是用给定的JSON例子。一步一步地探索dict。print(metarJSON), print(metarJSON['data']), ......每一步给你什么,从哪里开始抱怨?
python
json
FrenchGap
FrenchGap
发布于 2020-01-15
1 个回答
AmirHmZ
AmirHmZ
发布于 2020-01-15
已采纳
0 人赞同

json.loads()解析json字符串并返回一个字典,所以你可以用这种方式访问数值。

parsed = json.loads(req.text)