Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post boolean or integer value using volley

Tags:

java

android

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....

@Override

        protected Map<String, String> getParams() {

            Map<String, String> params = new HashMap<String, String>();
            params.put("name", "name");
            params.put("email", "[email protected]");
            params.put("pass", "password");

            return params;
        }
like image 319
Soham Avatar asked Oct 13 '14 19:10

Soham


2 Answers

JSONObject obj = new JSONObject();

obj.put("isboolean",false)

JsonObjectRequest req = new JsonObjectRequest(Constants.URL_PATH, obj,
                new Listener<JSONObject>() {


            @Override
            public void onResponse(JSONObject response) {


}, new ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
like image 140
Suhail Mehta Avatar answered Oct 05 '22 20:10

Suhail Mehta


JSONObject object = new JSONObject();
try {
    object.put("compression", false);
    object.put("instructions", true);
} catch (JSONException e) {
    e.printStackTrace();
}

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, API_URL, object, new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) {
        parseDirectionsData(response);
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        error.printStackTrace();
    }
}){
    @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        HashMap<String, String> params = new HashMap<>();
        params.put("loc", "-33.9717974,18.6029783");
        return params;
    }
};

Any of the parameters that are not Strings you can wrap them into the Json Object.

like image 31
Joseph Avatar answered Oct 05 '22 19:10

Joseph