【发布时间】:2014-02-14 07:21:32
【问题描述】:
我正在尝试编译我所有的 facebook 朋友用户 ID,但输出对我来说很难处理。我怎样才能简化?目前看起来是这样的:
{
u'friends': {
u'paging': {
u'next': u'https://graph.facebook.com/556702392/friends?access_token=-MYACCESSTOKEN-&limit=5000&offset=5000&__after_id=100005821213415'
},
u'data': [
{u'name': u'Ian Fung', u'id': u'419972'},
{u'name': u'Jason Turer', u'id': u'420694'},
...
]
}
...
}
这是我能想到的:
try:
resp = urllib2.urlopen(url)
contents = resp.read()
except urllib2.HTTPError, error:
contents = error.read()
json_encoded = json.loads(contents)
print json_encoded["data"]["id"]
如何只存储 ID?
【问题讨论】:
-
你试过什么?问题是您无法解析 JSON,无法从中提取值,...?你有错误吗?更具体并提供您的代码。
-
看来他需要提取id。 (他正在使用
json包)
标签: python json facebook api parsing