Create a JSON String with null value.
suggest changeIf you need to produce a JSON string with a value of null like this:
{
"name":null
}
Then you have to use the special constant JSONObject.NULL.
Functioning example:
put throws JSONException. JSONObject.NULL is not Java null. Passing Java null removes the key instead of storing a JSON null.
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", JSONObject.NULL);
String json = jsonObject.toString();
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents