org.json.jsonobject中的jsonobject.putopt和jsonobject.putonce是什么?

发布于 2025-01-28 05:04:56 字数 235 浏览 1 评论 0原文

jsonobject.putoptjsonobject.putonce in org.json.jsonobject的功能是什么?

jsonobject.putoptjsonobject.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦萦几度 2025-02-04 05:04:56

这里我从Oracle网站上得到的内容:

​这意味着您可以添加重复键(最终替换了JSONOBJECT中的现有密钥),还可以通过put添加空键/值。

putopt(字符串,对象)的作用与 put(string,object)相同,但是键和值都必须是非零的。

putonce(字符串,对象)方法也像 putopt(string,object),但是如果已经有相同值的密钥,则会引发例外。

Here what I got from oracle website:

enter image description here

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.

氛圍 2025-02-04 05:04:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文