8

jsonObject.accumulate("status",null);

I want to pass null as a value in json service call i try ""," ", NULL, nil,"null" but nothing helps

Could anyone have solution for this ?

1
  • jsonObject.accumulate("usertype", 1); jsonObject.accumulate("Userid", LoginActivity.user_id); jsonObject.accumulate("isSaved", true); jsonObject.accumulate("buyerId", 0); jsonObject.accumulate("status",null); jsonObject.accumulate("OrderNo",null); in above json service call i want to pass null in "status" & "OrderNo". Jun 7, 2016 at 13:15

1 Answer 1

6

Try using JSONObject.NULL instead of null, if you are using org.json.

Referenced from documentation.

edit

I tried, creating an json object with null as value, something like this.

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("Test", JSONObject.NULL);

and the output generated on printing it was, {"Test": null}

So, I guess this will do the magic for you. :)

6
  • 1
    JSONObject.Null is used for checking json object is null or not or i think its usefull at retriving time but i m trying to call .net service and at that time i want to pass null as a parameter. Jun 7, 2016 at 13:26
  • 1
    it will probably set value as "null". What are you expecting on server side? Jun 7, 2016 at 13:30
  • 1
    server side i m expecting null without "null" double quotes its like null data type Jun 7, 2016 at 13:31
  • 1
    "usertype" : "1", "buyerId" : 0, "isSaved" : true, "Userid" : 60, "OrderNo" : null, "ip" : "192.168.137.6", "status" : null, ......................see this is my iphone service call exactly i want like this null but want be able to send like this when i call services it will automatically remove those parameter which define as null. Jun 7, 2016 at 13:33
  • 1
    good news.. when you use JSONObject.NULL, it creates json like {"Test": null}. Just Tested. So now your .net server can easily convert it to its own null reference. Jun 7, 2016 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.