前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JSONObject put,accumulate,element的区别

JSONObject put,accumulate,element的区别

作者头像
用户5640963
发布2019-07-26 10:03:53
5450
发布2019-07-26 10:03:53
举报
文章被收录于专栏:卯金刀GG

public Object put (Object key, Object value) 将value映射到key下。如果此JSONObject对象之前存在一个value在这个key下,当前的value会替换掉之前的value

Associates the specified value with the specified key in this map(optional operation). If the map previously contained . a mapping for this key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true .))

public JSONObject accumulate (String key, Object value) 累积value到这个key下。这个方法同element()方法类似,特殊的是,如果当前已经存在一个value在这个key下那么一个JSONArray将会存储在这个key下来保存所有累积的value。如果已经存在一个JSONArray,那么当前的value就会添加到这个JSONArray中

。相比之下replace方法会替代先前的value

Accumulate values under a key. It is similar to the element method except that if there is already an object stored

under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already a

JSONArray, then the new value is appended to it. In contrast, the replace method replaces the previous value.

public JSONObject element (String key, Object value) 将键/值对放到这个JSONObject对象里面。如果当前value为空(null),那么如果这个key存在的话,这个key就会移除掉。如果这

个key之前有value值,那么此方法会调用accumulate()方法。

Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if it is

present. If there is a previous value assigned to the key, it will call accumulate.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档