gon250
gon250

Reputation: 3545

VolleyError is the value I want

I'm new using Vollay and I don't know if I'm doing something wrong.

I´m trying to get a json from an url and when I request it by "Vollay" It goes to the VolleyError and the error has the value I want.

Any idea why I'm getting it like an error? and how can I fix it?

Below you can see my code.

RequestQueue queue = Volley.newRequestQueue(this.getActivity());

    final ProgressDialog progressDialog = ProgressDialog.show(this.getActivity(), "Wait please","Loading..");

    JsonArrayRequest req = new JsonArrayRequest(Url, new Response.Listener<JSONArray>(){
        @Override
        public void onResponse(JSONArray response) {
            Log.e("My response", response.toString());
            progressDialog.cancel();
        }
    }, new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("My response", error.toString());
            progressDialog.cancel();
        }
    });

Thanks.

Url: [http://pipes.yahoo.com/pipes/pipe.run?_id=666721920db27c5f3d996add6cdc048b&_render=json&destino=Sevilla+Prado+S.S.&id_destino=994&id_origen=999&origen=Sanlucar+d+Barrameda]http://pipes.yahoo.com/pipes/pipe.run?_id=666721920db27c5f3d996add6cdc048b&_render=json&destino=Sevilla+Prado+S.S.&id_destino=994&id_origen=999&origen=Sanlucar+d+Barrameda

Error = com.android.volley.ParseError: org.json.JSONException: Value {"count":0,"value":{"title":"Get TimeTable Amarillos","description":"Pipes Output","link":"http://pipes.yahoo.com/pipes/pipe.info?_id=666721920db27c5f3d996add6cdc048b","pubDate":"Mon, 06 Oct 2014 18:14:20 +0000","generator":"http://pipes.yahoo.com/pipes/","callback":"","items":[]}} of type org.json.JSONObject cannot be converted to JSONArray

Problem was I was trying to get a JsonArrayRequest and the result is a JsonObje

JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, Url, null,
            new Response.Listener<JSONObject>()
            {
                @Override
                public void onResponse(JSONObject response) {
                    Log.e("Response", response.toString());
                    progressDialog.cancel();
                }
            },
            new Response.ErrorListener()
            {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e(TAG, "headers: " + error.networkResponse.headers);
                    Log.e(TAG, "statusCode: " + error.networkResponse.statusCode);
                    progressDialog.cancel();
                }
            }
    );

Upvotes: 0

Views: 243

Answers (1)

mmlooloo
mmlooloo

Reputation: 18977

Lets look at the response:

{

    "count": 0,
    "value": {
        "title": "Get TimeTable Amarillos",
        "description": "Pipes Output",
        "link": "http://pipes.yahoo.com/pipes/pipe.info?_id=666721920db27c5f3d996add6cdc048b",
        "pubDate": "Mon, 06 Oct 2014 18:22:13 +0000",
        "generator": "http://pipes.yahoo.com/pipes/",
        "callback": "",
        "items": [ ]
    }

}

this is a JSONObject so you must not use JsonArrayRequest, change that to JsonObjectRequest.

Upvotes: 1

Related Questions