我正在尝试在 Android 应用程序中使用 FQL 解析从 Facebook API 获取的结果(JSON)。
我已经能够解析除这部分之外的所有结果集:
[10151392619250579,10151392618640579,10151392618590579,10151392618785579,10151392618835579,10151392618885579,10151392619010579,10151392619155579]
我正在做的 FQL 查询是:
SELECT app_data FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid = me() AND type = 'newsfeed') AND is_hidden = 0 LIMIT 200
它返回如下结果:
{
"app_data": {
"attachment_data": "[]",
"images": "[10151392619250579,10151392618640579,10151392618590579,10151392618785579,10151392618835579,10151392618885579,10151392619010579,10151392619155579]",
"photo_ids": [
"10151392619250579",
"10151392618640579",
"10151392618590579",
"10151392618785579",
"10151392618835579",
"10151392618885579",
"10151392619010579",
"10151392619155579"
]
}
}
这是我用来获取数据的代码:
// GET THE APP DATA
if (JOFeeds.has("app_data")) {
String strAppData = JOFeeds.getString("app_data");
if (strAppData.equals("[]")) {
// DO NOTHING
} else {
JSONObject JOAppData = new JSONObject(strAppData);
if (JOAppData.has("photo_ids")) {
String strPhotoIDS = JOAppData.getString("photo_ids");
JSONArray JAPhotoIDS = new JSONArray(strPhotoIDS);
Log.e("JAPhotoIDS", JAPhotoIDS.toString());
for (int j = 0; j < JAPhotoIDS.length(); j++) {
JSONObject JOPhotoIDS = JAPhotoIDS.getJSONObject(j);
Log.e("PHOTO IDS", JOPhotoIDS.toString());
}
}
}
}
然而,logcat 总是显示这个错误:
12-13 15:54:36.390: W/System.err(5841): org.json.JSONException: Value 10151392619250579 at 0 of type java.lang.Long cannot be converted to JSONObject
显然我在编码方面是错误的。任何人都可以就正确的方法/代码应该是什么提供任何建议吗?