1

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.

4

1 回答 1

1

这意味着nullJson Object 中的标准 Java 值会导致它们被忽略并且不会出现在输出中。这样做是为了压缩输出。哨兵JSONObject.NULL将在输出字符串中添加 null 。

一个例子会让你清楚

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

这将给出类似的输出

{"Last Name":null}
于 2013-08-13T10:17:34.653 回答