Skip to content

Instantly share code, notes, and snippets.

@roshanpal
Created July 20, 2016 16:15
Show Gist options
  • Save roshanpal/a736b1143df8c1b80e99a1f97ed52522 to your computer and use it in GitHub Desktop.
Save roshanpal/a736b1143df8c1b80e99a1f97ed52522 to your computer and use it in GitHub Desktop.
JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject jp = response.getJSONObject(i);
Post p = new Post(
jp.getInt("userId"),
jp.getInt("id"),
jp.getString("title"),
jp.getString("body")
);
mPosts.add(p);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment