How to post boolean or integer value using volley

前端 未结 4 1711
予麋鹿
予麋鹿 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条回答
  •  萌比男神i
    2021-01-18 21:52

    If you have a custom Request, you could just override the getBody method and go to town:

    @Override
    public byte[] getBody(){
            JSONObject jsonObject = new JSONObject();
            String body = null;
            try{
                //Here are your parameters:
                jsonObject.put("name", "geronimous");
                jsonObject.put("age", 998);
                jsonObject.put("happy", true);
    
                body = jsonObject.toString();
            } catch (JSONException e){
                e.printStackTrace();
            }
            try{
                return body.toString().getBytes("utf-8");
            } catch (UnsupportedEncodingException e){
                e.printStackTrace();
            }
            return null;
    
    }
    

    Just make sure you have the content type as application/json on the headers

提交回复
热议问题