Frage

What does the sentinel value NULL mean in Android Developer JSONObject reference page, cited here for convenience:

Warning: this class represents null in two incompatible ways: the standard Java null reference, and the sentinel value NULL. In particular, calling put(name, null) removes the named entry from the object but put(name, JSONObject.NULL) stores an entry whose value is JSONObject.NULL.


UPDATE

All that I can find online is this.

War es hilfreich?

Lösung

This means that the Standard Java null values in Json Object causes them to be ignored and do-not appear in the output. This is baiscally done to compact the output. Where as the sentinel JSONObject.NULL will add null in the output string.

An example will make you clear

JSONObject jObject = new JSONObject();
jObject.put("First Name", null);
jObject.put("Last Name", JSONObject.NULL);
//Print jObject
Log.d("JSON OBJECT", jObject.toString());

This will give the output like

{"Last Name":null}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top