如何解析 Facebook 数据 [英] How to Parse Facebook Data
问题描述
我在正确解析 Facebook 数据时遇到了一些问题.
I am having a few problems getting Facebook data to parse properly.
我正在努力实现应用程序的一部分,以允许用户在应用程序中选择和使用他们自己的 facebook 照片之一.我已经让 facebook 登录/注销代码正常工作,我目前正在获取令牌(一旦登录)以收集用户相册信息.权限集也运行良好,但是我现在坚持尝试正确解析 JSON 信息.这是我需要解析的信息的示例片段:
I am working on implementing part of an application to allow a user to select and use one of their own facebook photos within the app. I have gotten the facebook login/logout code working and I am currently getting the token (once logged in) in order to gather the users Album information. The permission set is also working nicely, however I am now stuck at trying to get the JSON information to parse correctly. Here is a sample snippet of the information I need to parse:
"data": [
{
"id": "3486732467234",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=434235&id=324343&aid=2430",
"cover_photo": "3489234432",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T23:01:16+0000",
"updated_time": "2011-03-18T19:46:43+0000",
"can_upload": true
},
{
"id": "4043544665",
"from": {
"name": "Persons Name",
"id": "Persons ID"
},
"name": "Vacation 2",
"location": "City",
"link": "https://www.facebook.com/album.php?fbid=4043434665&id=508154335&aid=2555",
"cover_photo": "5434543",
"privacy": "everyone",
"count": 60,
"type": "normal",
"created_time": "2007-06-03T22:53:03+0000",
"updated_time": "2011-03-18T19:45:55+0000",
"can_upload": true
}],
...more paging JSON information ...}}
我需要能够提取相册信息,以便在列表中显示相册名称(并在另一个查询中使用 ID).一旦我可以显示相册,我就会使用这些 ID 执行另一个查询以从该相册中获取照片.我也可以再次取回该信息,我只是不确定如何正确解析它.
I need to be able to pull the album information in order to display the photo album names in a list (and use the ID in another query). Once I can get the albums to show, I would then use those IDs to perform another query to get the photos from that album. Again I can also get that information back, I am just not sure how to properly parse it.
如果有人能够将其解析为列表视图,任何有用的提示将不胜感激.
Any useful tips that someone might have in being able to parse this into a listview would be greatly appreciated.
我需要从第一个列表中提取第一个 ID 和专辑名称(id":3486732467234"和name":Vacation")
I need to target pulling the first ID and the Album name ("id": "3486732467234" and "name": "Vacation" from the first listing)
推荐答案
为什么不试试 json 类...
why don't you try with the json classes...
像这样:
jsonObject = new JSONObject(your_data);
jArray = jsonObject.getJSONArray("data");
for(int i =0;i<jArray.length();i++){
String name= jArray.getJSONObject(i).getString("name");
String location= jArray.getJSONObject(i).getString("location");
等
这篇关于如何解析 Facebook 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!