我正在使用Twitch API,并且我有一个大型嵌套字典。我如何筛选它?Python通过嵌套字典排序
>>> r = requests.get('https://api.twitch.tv/kraken/streams/sibstlp', headers={'Accept': 'application/vnd.twitchtv.v2+json'})
则:
>>> print r.text
#large nested dictionary starting with
#{"stream":{"_links":{"self":"https://api.twitch.tv/kraken/streams/sibstlp"},
有趣的是:
>>> r.text
# large nested dictionary starting with
#u'{"stream":{"_links":{"self":"https://api.twitch.tv/kraken/streams/sibstlp"},
有谁知道为什么r.text是从打印r.text不同?
我如何通过字典来获取我要查找的信息? 我目前想:
>>> r.text[stream]
NameError: name 'stream' is not defined
感谢
谢谢你的解释。我现在需要去了解json :) – IdeoREX
Python的json库非常有用:http://docs.python.org/2/library/json.html – Brien