2016-09-24 38 views

回答

0

您必須使用JsonArrayRequest對於JSONArray參數。

+0

但此Web API正在返回JSONObject,它需要JSONArray作爲參數。 –

+0

然後把jsonarray放入jsonobject中 –

+0

API只能接受JSONArray,那我怎樣才能發送JSONObject到Web API? –

0

`JSONArray jsonArray1 = new JSONArray();

JsonObjectRequest jsonRequest = new JsonObjectRequest 
      (Request.Method.POST, url, jsonArray1, new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject score_response) { 
        // the response is already constructed as a JSONObject! 

        Log.e(TAG, score_response.toString()); 

       } 
      }, new Response.ErrorListener() { 

       @Override 
       public void onErrorResponse(VolleyError error) { 
        error.printStackTrace(); 
       } 
      }); 

    Volley.newRequestQueue(this).add(jsonRequest);` 

jsonArray1在這裏不兼容。它顯示錯誤。如果我在這裏把JSONObject,那麼它工作正常。

相關問題