Reputation: 6450
I am trying to get the user's friends who have the app downloaded, I am using the following code
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());
The code above makes a successful call. I am having trouble with getting what the call returns, which looks like this (A JSONArray)
[{"uid":555555555},{"uid":000000000},{"uid":111111111},{"uid":222222222},{"uid":333333333}]
How do I put this information into something like an ArrayList?
Here is the RequestListener I am using.
private class FQLListener implements RequestListener
{
@Override
public void onComplete(String response, Object state)
{
//get info here
}
}
Upvotes: 0
Views: 543
Reputation: 6318
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();
}
Upvotes: 0
Reputation: 505
Look at http://developer.android.com/reference/org/json/JSONArray.html to read JSONArray. You can try something like this :
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){}
}
Upvotes: 1