2017-02-14 64 views
1

我正在嘗試將JsonObject發佈到我的API並從服務器獲取JsonArray響應。我會怎麼做呢?我得到一個異常錯誤,如果我嘗試發佈JSONObject並獲取JSONArray請求Volley

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url_test,new JSONObject(params), 
      new Response.Listener<JSONObject>() { 
       @Override 
+0

請你告訴它'Exception'被拋出? –

+0

發佈崩潰日誌和完整代碼.. – rafsanahmad007

+0

com.android.volley.ParseError:org.json.JSONException: – pavlos

回答

0

試試這些..

url = "http://your Api post"; 
    StringRequest postRequest = new StringRequest(Request.Method.POST, url, 
     new Response.Listener<String>() 
     { 
      @Override 
      public void onResponse(String response) { 
       // response 
       Log.d("Response", response); 
      } 
     }, 
     new Response.ErrorListener() 
     { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       // error 
       Log.d("Error.Response", response); 
      } 
     } 
    ) { 

//You send the key and value to server you enter here 


@Override 
    protected Map<String, String> getParams() 
    { 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put("key", "value"); 

      return params; 
    } 
}; 
queue.add(postRequest);