0

我正在尝试获取已下载该应用程序的用户朋友,我正在使用以下代码

         String query = "SELECT uid FROM user WHERE is_app_user=1 and uid IN  (SELECT uid2 FROM friend WHERE uid1 =" + fbId + ")";
         Bundle params = new Bundle();
         params.putString("method", "fql.query");
         params.putString("query", query);
         mAsyncFacebookRunner.request(null, params, new FQLListener());

上面的代码成功调用。我无法获取调用返回的内容,如下所示(A JSONArray)

    [{"uid":555555555},{"uid":000000000},{"uid":111111111},{"uid":222222222},{"uid":333333333}]

如何将这些信息放入 ArrayList 之类的东西中?

这是我正在使用的 RequestListener。

 private class FQLListener implements RequestListener
    {

        @Override
        public void onComplete(String response, Object state) 
        {
            //get info here
        }
             }
4

2 回答 2

1

查看http://developer.android.com/reference/org/json/JSONArray.html来阅读 JSONArray。你可以尝试这样的事情:

JSONArray json = new JSONArray(server_response);
ArrayList<String> list = new ArrayList<String>();

for(int i = 0; i < json.length(); ++i){
    try{
        String uid = json.getJSONObject(i).getString("uid");
        list.add(uid);
    }
    catch(JSONException e){}
}
于 2012-05-23T07:10:25.793 回答
0
ArrayList<String> uids = new ArrayList<String>();

try {
    JSONArray jsonArr = new JSONArray(response);

    for (int i = 0; i < jsonArr.length(); i++)
    {
        uids.add(jsonArr.getJSONObject(i).getString("uid"));
    }
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
于 2012-05-23T07:13:51.010 回答