我正在使用 facebook graph api 来获取当前的用户好友列表。
我有执行此操作的正确权限,并且返回的 JSON 对象返回如下内容:
{
"data": [
{
"name": "name1",
"id": "11111"
},
{
"name": "name2",
"id": "2222"
},
{
"name": "name3",
"id": "33333"
}],
"paging": {
"next": "https://graph.facebook.com/613714903/friends?format=json&limit=5000&offset=5000&__after_id=100003711723705"
}
}
据我了解,这是一个 JSONArray,每个用户名和 id 都是一个 JSONObjects .. 我编写了这段代码来对其进行编码:
FacebookFriend[] facebookFriends = null;
try {
facebookResults = facebookResults.getJSONArray(0);
facebookFriends = new FacebookFriend[facebookResults.length()];
for (int i=0; i < facebookResults.length(); i++)
{
JSONObject json = new JSONObject(facebookResults.getJSONObject(i).toString());
facebookFriends[i].setuId(json.getString("id"));
facebookFriends[i].setProfilePicture(getProfilePicture(json.getString("id")));
facebookFriends[i].setGender(getGender(json.getString("id")));
}
} catch (JSONException e) {
Log.e("Facebook Error", e.toString());
alert("Facebook Error", e.toString(),"ok");
}
我收到以下错误:
org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject
我真的不明白为什么...