Reputation: 1205
I use this code to make requests to a server, it usually works fine but sometimes it throws some errors since its under development, however if it throws an error volley tries to parse it into a JsonObject and will inevitably fail.
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.POST, baseUrl, postparams, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.w("Response", response.toString());
callBackActivity.JsonCallback(response, "grupos");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callBackActivity.ErrorCallback(error, "grupos");
}
});
So is there any way to know whats the raw response of the server before parsing it into a JsonObject?
Upvotes: 0
Views: 61
Reputation: 10829
Instead of JSONObjecRequest
try StringRequest
which will give the response in string. Log this response and look what is causing the error, then you can revert it back to JSONObjectRequest
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.v(response)
try {
JSONObject object = new JSONObject(response);
}
} catch (Exception e) {
Log.v("exception is " + e.toString());
} }
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//error log
}
});
Upvotes: 2