Reputation: 4973
I am using net.sf.json.JSONObject. It will remove key
if my value is null while I am trying to put data in Json object using put method.
Is there any way to keep my key as it is in my object even my value is null?
for ex.
JSONObject json = new JSONObject();
json.put("myKey",null);
Then my output is : {}
But I want
output : {"myKey",""}
How can I do?
Upvotes: 1
Views: 11142
Reputation: 1
JSONObject backJsonObject = new JSONObject();
backJsonObject.put("111", "NULL");
backJsonObject.put("111", "null"); how to output {"111":"null"} instead of {"111":null} in net.sf.json
Upvotes: -2
Reputation: 163
JSONObject.NULL
is for Apache Commons JSONObject.
Try the following instead:
json.put("key", JSONNull.getInstance())
Here follows the documentation for net.sf.json.JSONObject
:
http://json-lib.sourceforge.net/apidocs/index.html
Search for JSONNull
to find out more.
Upvotes: 1