How to post boolean or integer value using volley

前端 未结 4 1746
予麋鹿
予麋鹿 2021-01-18 21:05

I want to post boolean,double data using volley library.I am not getting how to use it.Is there any other process.Thanks in advance.

Here is my method....

         


        
4条回答
  •  半阙折子戏
    2021-01-18 22:05

    Here is the complete request of a volley call. You can change the method call. You can pass any type of parameters as a JSON object You can set request header

                JSONObject jsonObject = new JSONObject();
                jsonObject.put("stringValue", "abc");
                jsonObject.put("doubleValue", 13.066);
                jsonObject.put("integerValue", 120);
                jsonObject.put("booleanValue", true);
    
                JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, getString(R.string.api_url), jsonObject,
                        new Response.Listener() {
                            @Override
                            public void onResponse(JSONObject response) {
                                getJsonResult(response);
                            }
                        },
                        new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
    
                            }
                        }
                ) {
                    @Override       //Send Header
                    public Map getHeaders() throws AuthFailureError {
    
                        Map params = new HashMap<>();
                        params.put("api_call_header", "header_value");
    
                        return params;
                    }
                };
                // Adding request to request queue
                AppController.getInstance().addToRequestQueue(request);`enter code here`
    

提交回复
热议问题