我一直在考虑以下内容: https ://developers.facebook.com/docs/howtos/androidsdk/3.0/run-fql-queries/#step2
它具有以下代码(为简单起见,我更改了 fql 查询):
queryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fqlQuery = "SELECT name FROM user WHERE uid IN " +
"(SELECT uid2 FROM friend WHERE uid1 = me()LIMIT 2)";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
Log.i(TAG, "Result: " + response.toString());
}
});
Request.executeBatchAsync(request);
}
});
专门查看 Log.i,response.toString() 会返回以下格式的内容:
Result: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[{"name":"John Doe"},{"name":"Jake Josh"}]}}, error: null, isFromCache:false}
现在我的假设是响应是一个 json obj 所以我尝试了这样的事情:
JSONObject json=new JSONObject(response);
但这不起作用,所以我不确定如何阅读我得到的回复,严格来说,我只想遍历名称,但无法弄清楚如何实际阅读回复