How do you set a value to null with org.json.JSONObject in java?
Solution 1:
Try to set JSONObject.NULL
instead of null
:
A sentinel value used to explicitly define a name with no value. Unlike null, names with this value:
- show up in the names() array
- show up in the keys() iterator
- return true for has(String)
- do not throw on get(String)
- are included in the encoded JSON string.
This value violates the general contract of equals(Object) by returning true when compared to null. Its toString() method returns "null".