Right there in the documentation, in the first paragraph:
值不能为null
、NaN
s、无穷大或此处未列出的任何类型.
So yes, it is "...something that null
values are not included..." (edit: that was a quote from your original question; your updated question changes it to "uninitialized values" but the default value of an object reference is null
, so...)
It's a "feature" of that class, though; JSON itself understands null
just fine. Further down in the documentation it says you use a "sentinal value," NULL
, to represent null
. Which seems...odd. There's a note about it:
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
.
所以:
params.put(KEY_TOKEN, token == null ? JSONObject.NULL : token);