2014-10-05 36 views
0

我是新来的使用Vollay,我不知道我是否做错了什么。VolleyError是我想要的值

我试图从一个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:值{ “计数”:0 “值”:{ “标题”: “获取时间表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“:[]}} 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(); 
       } 
      } 
    ); 
+0

我认为**响应**的响应标题有500的错误。请检查其他东西,如RESTClient for mozilla。 – mmlooloo 2014-10-06 03:00:04

+0

我再次检查它,状态是200 OK。我会试着弄清楚为什么会这样。我今晚会尝试一个不同的路径请求,看看它是否有效。 – gon250 2014-10-06 08:26:16

+0

我已经尝试了不同的路径,我仍然得到VollayError对象内的json。 – gon250 2014-10-06 17:53:39

回答

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

+0

好的,谢谢让我试着用Volley来实现它,因为我从来没有尝试过它。 – gon250 2014-10-06 18:33:49

+0

只需将'JsonArrayRequest'更改为'JsonObjectRequest'。 – mmlooloo 2014-10-06 18:34:46

+0

谢谢,它现在工作正常。是我的错。 – gon250 2014-10-06 19:00:27