Skip to content

Instantly share code, notes, and snippets.

@msomu
Created October 6, 2014 16:02
Show Gist options
  • Save msomu/5cabaeb6aac62c93d2be to your computer and use it in GitHub Desktop.
Save msomu/5cabaeb6aac62c93d2be to your computer and use it in GitHub Desktop.
Making JSON object Request
// Tag used to cancel the request
String tag_json_obj = "json_obj_req";
String url = "http://api.androidhive.info/volley/person_object.json";
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Volley:", response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Volley:", "Error: " + error.getMessage());
// hide the progress dialog
pDialog.hide();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment