发布JSONObject并获取JSONArray请求Volley

时间:2017-02-14 10:16:18

标签: android json post android-volley

我目前正在尝试将JsonObject发布到我的API并从服务器获取JsonArray响应。我该怎么办?如果我尝试

,我会收到异常错误
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url_test,new JSONObject(params),
            new Response.Listener<JSONObject>() {
                @Override

1 个答案:

答案 0 :(得分: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);