Reputation: 3545
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.
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
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