org.json.jsonobject中的jsonobject.putopt和jsonobject.putonce是什么?
jsonobject.putopt
和jsonobject.putonce
in org.json.jsonobject
的功能是什么?
或jsonobject.putopt
和jsonobject.putonce
in org.json.jsonobject
做什么?
What is the functionality of JSONObject.putOpt
and JSONObject.putOnce
in org.json.jsonobject
?
Or what does JSONObject.putOpt
and JSONObject.putOnce
in org.json.jsonobject
do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里我从Oracle网站上得到的内容:
这意味着您可以添加重复键(最终替换了JSONOBJECT中的现有密钥),还可以通过put添加空键/值。
putopt(字符串,对象)的作用与 put(string,object)相同,但是键和值都必须是非零的。
putonce(字符串,对象)方法也像 putopt(string,object),但是如果已经有相同值的密钥,则会引发例外。
Here what I got from oracle website:
So, put(String, Object) will act without any condition. This means you can add duplicate keys(eventually replace the existing key in the JSONObject), and also add null keys/values by put.
The putOpt(String, Object) acts the same as put(String, Object), but both the key and the value has to be non-null.
The putOnce(String, Object) method is also like putOpt(String, Object), but throws an exception if there is already a key of the same value.
putopt
将有助于添加可选的键值对,而无需明确的空检查。putonce
当您要确保仅将密钥添加到JSONOBJECT中时,将很有用。putOpt
will be useful for adding optional key-value pairs without needing explicit null checks.putOnce
will be useful when you want to ensure a key is added only once to the JSONObject.