Python3的JSON

2024-04-27 03:38:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要阅读这个JSON网址:http://www.jsoneditoronline.org/?url=https://api.twitch.tv/kraken/streams/hazretiyasuo

我的代码:

geourl = "https://api.twitch.tv/kraken/streams/hazretiyasuo"

response = urllib.request.urlopen(geourl)
content = response.read()
data = json.loads(content.decode("utf8"))
for row in data['stream']
    print data['game']

我能读'stream',但我不能读'game',游戏在流中。你知道吗


Tags: httpsapigamejsondatastreamresponsecontent
1条回答
网友
1楼 · 发布于 2024-04-27 03:38:57

当我运行问题中的代码,然后打印出返回的json时,我得到以下结果:

{
  "_links": {
    "channel": "https://api.twitch.tv/kraken/channels/hazretiyasuo",
    "self": "https://api.twitch.tv/kraken/streams/hazretiyasuo"
  },
  "stream": null
}

无法获取data['game']的原因是,返回的json不包含该信息。你知道吗

相关问题 更多 >