【问题标题】:VolleyError is the value I wantVolleyError 是我想要的值
【发布时间】:2014-11-30 05:44:44
【问题描述】:

我是使用 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

Error = com.android.volley.ParseError: org.json.JSONException: Value {"count":0,"value":{"title":"Get TimeTable Amarillos","description":"Pipes Output" ,"链接":"http://pipes.yahoo.com/pipes/pipe.info?_id=666721920db27c5f3d996add6cdc048b","pubDate":"2014 年 10 月 6 日星期一 18:14:20 +0000","generator": org.json.JSONObject 类型的 "http://pipes.yahoo.com/pipes/","callback":"","items":[]}} 无法转换为 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();
                }
            }
    );

【问题讨论】:

  • 我认为您的 response 的响应标头有 500 的错误。请检查 RESTClient for mozilla 等其他内容。
  • 我又检查了一遍,状态是200 OK。我会试着弄清楚为什么会这样。今晚我将尝试对不同路径的请求,看看它是否有效。
  • 我尝试了不同的路径,但我仍然在 VollayError 对象中获取 json。
  • 错误类型是什么?
  • 我已经添加了我遇到的错误,看起来它无法投射它。

标签: android android-volley


【解决方案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

【讨论】:

  • 好的,谢谢让我尝试用 Volley 实现它,因为我从未尝试过。
  • 只需在你的截击中将JsonArrayRequest 更改为JsonObjectRequest
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-23
  • 1970-01-01
  • 2015-04-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多