After make a request the volley listener called is onErrorResponse and for my surprise the error message is the callback that I wanted from my server, a json with correct datas.
What is strange thats a parseError but how's a parse error if I make the parse in the onResponse listener.
I'm new in android.
My method:
public void getAllEstablishmentsRequest(){
String url = "http://myServer.com/something";
RequestQueue requestQueue = Volley.newRequestQueue(this);
JsonArrayRequest request = new JsonArrayRequest(url,
new Response.Listener<JSONArray>(){
@Override
public void onResponse(JSONArray response) {
try {
JSONObject object = new JSONObject(response.toString());
JSONArray Jarray = object.getJSONArray("data");
for (int i = 0; i < Jarray.length(); i++) {
JSONObject Jasonobject = Jarray.getJSONObject(i);
}
} catch (JSONException e){
Log.e("Volley", "Error JSON");
}
}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Log.e("Volley", "Error - requisição das campanhas de Eutrofização");
System.out.println(error);
}
}
);
requestQueue.add(request);
}
Error: com.android.volley.ParseError: org.json.JSONException: Value {"data":{"establishments":[{"created_by":1,"phone":"(85) 3246-3834","teste":1453583589,"neighborhood":"Joaquim Távora","last_promotion":"2015-10-06 12:42:01","days_last_promotion":110,"id":2,"distance":0,"updated_at":"2015-10-06 12:42:01","address":"Av. Barão de Studart, 2675","name":"São Luiz","updated_by":1,"created_at":"2015-05-31 19:48:58","active":true,"longitude":"-38.510342","latitude":"-3.746922"},{"created_by":3,"phone":"(85) 4008-2444","teste":1453583589,"neighborhood":"Messejana","last_promotion":"2016-01-22 13:45:30","days_last_promotion":2,"id":96,"distance":0,"updated_at":"2016-01-22 13:45:30","address":"Av. Frei Cirilo, 4290","name":"Pinheiro","updated_by":3,"created_at":"2015-12-24 14:27:29","active":true,"longitude":"-38.495841","latitude":"-3.821112"},{"created_by":3,"phone":"","teste":1453583589,"neighborhood":"Vila Peri","last_promotion":"2016-01-21 19:06:16","days_last_promotion":2,"id":140,"distance":0,"updated_at":"2016-01-21 19:06:16","address":"Rua Cônego de Castro, 3859","name":"Cometa","updated_by":null,"created_at":"2016-01-21 18:21:41","active":true,"longitude":"-38.587981","latitude":"-3.800781"}],"establishments_total":134},"success":"YES","time":"2016-01-23 18:13:09"} of type org.json.JSONObject cannot be converted to JSONArray