VolleyError是我想要的值

时间:2014-10-05 23:15:27

标签: android android-volley

我是新手使用Vollay,我不知道我做错了什么。

我试图从一个url获取一个json,当我通过“Vollay”请求它时,它转到VolleyError并且错误具有我想要的值。

知道为什么我会把它变成错误吗?我该如何解决?

下面你可以看到我的代码。

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();
        }
    });

感谢。

网址:[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

错误= 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”:“星期一,2014年10月6日18:14:20 +0000”,“发电机”: “http://pipes.yahoo.com/pipes/”,“回调”:“”,“项目”:[]}}类型org.json.JSONObject无法转换为JSONArray

问题是我试图获得JsonArrayRequest,结果是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();
                }
            }
    );

1 个答案:

答案 0 :(得分:1)

让我们看看回应:

{

    "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": [ ]
    }

}

这是JSONObject,因此您不能使用JsonArrayRequest,请将其更改为JsonObjectRequest