Skip to content

Instantly share code, notes, and snippets.

@alexfaber2011
Created May 9, 2015 16:47
Show Gist options
  • Save alexfaber2011/5a79005196f40e3a0142 to your computer and use it in GitHub Desktop.
Save alexfaber2011/5a79005196f40e3a0142 to your computer and use it in GitHub Desktop.
Converting JSONObject to POJO
return new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
VolleyLog.v(response.toString());
List<Challenge> challenges = new ArrayList<Challenge>();
//iterate over each JSONObject
for(int i = 0; i < response.length(); i++){
try {
JSONObject obj = (JSONObject) response.get(i);
String JSONString = obj.toString();
Gson gson = new GsonBuilder().create();
challenges.add(gson.fromJson(JSONString, Challenge.class));
}catch(JSONException e){
e.printStackTrace();
Log.e(TAG, "Unable to extract JSON");
}
}
callback.onRequestCompleted(challenges);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment