Created
May 9, 2015 16:47
-
-
Save alexfaber2011/5a79005196f40e3a0142 to your computer and use it in GitHub Desktop.
Converting JSONObject to POJO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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