Twitter API会列出如下实体的列表:
[{'expanded_url': 'http://twitter.com/voxdotcom/status/458708072131592194/photo/1', 'display_url': 'pic.twitter.com/uc3j0nU8uf', 'url': 'http://t.co/uc3j0nU8uf', 'media_url_https': 'https://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png', 'id_str': '458708071875764224', 'sizes': {'small': {'h': 256, 'resize': 'fit', 'w': 340}, 'large': {'h': 773, 'resize': 'fit', 'w': 1023}, 'medium': {'h': 453, 'resize': 'fit', 'w': 599}, 'thumb': {'h': 150, 'resize': 'crop', 'w': 150}}, 'indices': [88, 110], 'type': 'photo', 'id': 458708071875764224, 'media_url': 'http://pbs.twimg.com/media/Bl2oj5_CYAAO72v.png'}]
它看起来像字典,但实际上是一个列表。阿格。在
如何访问特定条目?例如,如果我想要扩展的\u url值,获得它的最佳方法是什么?在
谢谢。在
*感谢您的快速回复。在
看起来您得到的是被解析为python对象的JSON。仔细看-你得到的是一个只有一个元素的列表。在
所以你需要做的就是去掉第一个元素,也就是你想要的东西。如果你叫这个东西
my_data
,那么你需要my_data[0]
。这就是字典,你可以像平常一样访问它里面的元素。在在
0
位置索引列表以获取字典:你得到的是一个^{} ,里面有一个字典项。通过
0
索引获取字典:另外,用^{} 进行打印有助于了解数据结构的组成:
^{pr2}$相关问题 更多 >
编程相关推荐