`
happy90
  • 浏览: 61400 次
  • 性别: Icon_minigender_1
  • 来自: 中国
社区版块
存档分类
最新评论

JSONObject put accumulate element 方法区别

 
阅读更多

JSONObject 几个方法的区别

 

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.

 

转自 http://blog.csdn.net/cocodehouse/article/details/5996088 ,保存这这里方便下次查看

 

分享到:
评论

相关推荐

    java的JsonObject对象提取值方法

    下面小编就为大家分享一篇java的JsonObject对象提取值方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

    创建JSONObject的四个常用方法

    基于json-lib.jar包 创建JSONObject的四个常用方法 基于json-lib.jar包Json实例程序

    JSON字符串转换JSONObject和JSONArray的方法

    一....二.具体转化过程 //JSONObject String jsonMessage = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}...JSONObject myJsonObject = new JSONObject(jsonMessage); //获取对应的值 value1 = myJsonObject.g

    android jsonobject.tobean方法

    在web中的jsonobject有个直接可以tobean的方法用起来非常方便,可android没有,所以通过反射机制学习web中的jsonobject写了一个jsonobject的tobean,方便使用.

    Json解析库JsonObject

    方便好用的json解析库,每个json元素都是...在调用此对象的一些方法,可以方便的把数据放到JsonObject 对象中 通过jsonObject .getJsonElement(key)可以方便的得到JsonElement该对象,接着可以方便的得到你想要的数据

    JsonObject(免分)

    JsonObject

    JSONObject相关依赖架包

    JSONObject相关依赖架包,包含1、com.alibaba.fastjson.JSONArray依赖jar 2、net.sf.json.JSONObject依赖jar

    JsonObject

    引用using Xfrog.Net; 用法如: JsonObject newObj = new JsonObject("json字符串"); String errorCode = newObj["error_code"].Value;//获取其中的属性值。

    JsonObject转换Date日期

    JsonObject转换Date日期的时候出现问题解决date封装成json数据出现的问题

    操纵JsonObject的方法.pdf

    操纵JsonObject的方法.pdf操纵JsonObject的方法.pdf

    JSONObject的lib库文件

    自己测试通过。 JSONObject obj = new JSONObject(); obj.put("1", 1); System.out.println(obj); 测试结果: {"1":1}

    org.json.JSONObject引用依赖包

    org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包

    jsonObject

    jsonObject、jsonArray

    JAVA JSONObject Jar包

    JAVA JSONObject Jar包

    JSONObject

    文件名称:JSONObject.rar(可用其他解压器解压),内含文件若干(6个)如下 commons-beanutils-1.9.1.jar commons-collections-3.2.1.jar commons-lang-2.6.jar commons-logging-1.1.1.jar ezmorph-1.0.6.jar json-lib-...

Global site tag (gtag.js) - Google Analytics