我可以从下面的Json
数据访问next
内的链接吗?我是这样做的
data = json.loads(html.decode('utf-8'))
for i in data['comments']:
for h in i['paging']:
print(h)
{
因为comments
是一个主对象。在comments
中有三个子对象data
、paging
和summary
。上面的代码也是这样做的,在comments
内部,因为paging
是多个其他对象的对象,在循环和打印中。它给出了错误
for h in i['paging']: TypeError: string indices must be integers
"comments": {
"data": [
{
"created_time": "2016-05-22T14:57:04+0000",
"from": {
"id": "908005352638687",
"name": "Marianela Ferrer"
},
"id": "101536081674319615443",
"message": "I love the way you talk! I can not get enough of your voice. I'm going to buy Seveneves! I'm going to read it this week. Thanks again se\u00f1or Gates. I hope you have a beautiful day:-)"
}
],
"paging": {
"cursors": {
"after": "NzQ0",
"before": "NzQ0"
},
"next": "https://graph.facebook.com/v2.7/10153608167431961/comments?access_token=xECxPrxuXbaRqcippFcrwZDZD&summary=true&limit=1&after=NzQ0"
},
"summary": {
"can_comment": true,
"order": "ranked",
"total_count": 744
}
},
"id": "10153608167431961"
}
您在“comments”中进行迭代,结果得到三个对象:
data
、paging
和summary
。您只需要paging
,但是您的第一个for循环希望您遍历所有其他的for循环。你知道吗因此,当它以
data
开头时,您试图调用data['paging']
,但这不起作用,因为data
的值是一个列表,而不是一个字典。你知道吗要立即访问
paging
:相关问题 更多 >
编程相关推荐