下面是我在 JSON 对象中获取组帖子的代码。此 JSON 对象包含“数据”的 JSON 数组。这进一步包含用于消息(或帖子状态)的单独 JSON 数组。
GraphRequest.newGraphPathRequest(
accessToken, "/id/posts",
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse graphResponse) {
try {
graphResponse.getRawResponse();
m=graphResponse.getJSONObject();
JSONArray n=m.getJSONArray("data");
messages=new String[n.length()];
for(int i=0;i<n.length();i++) {
JSONObject a = n.getJSONObject(i);
messages[i]=a.optString("message");
}
list.setAdapter(new ArrayAdapter<String> (fb.this,android.R.layout.simple_list_item_1,messages));
} catch (Exception e) {
Toast.makeText(fb.this, "error is: " + e.toString(), Toast.LENGTH_LONG).show();
}
}
}).executeAsync();