jsonobject的element和accumulate
来源:互联网 发布:linux内核用在哪 编辑:程序博客网 时间:2024/05/22 07:55
package com.test;import net.sf.json.JSONArray;import net.sf.json.JSONObject;/** * 测试element * 和accumulate * @author admin * */public class Snippet { public static void main(String[] arg){ JSONObject jsonAddr = new JSONObject(); jsonAddr.put("city", "厦门市"); jsonAddr.put("street", "博物馆"); JSONObject json = new JSONObject(); json.put("user", "wzj");//增加key值 json.put("age", 12); json.put("addr", jsonAddr); //增加一个对象到该key下,嵌套json json.put("tel", "1865010"); json.accumulate("tel", "1516003");//积累这个value到该key下,如果key存在,则该key的值为数组 json.put("age", 20);//如果该key已经存在则覆盖原来的值 json.put("lover", "secret"); json.element("lover", "secret2");//这个看文档是说,如果值原来存在的话会调用accumulate,但发现这里其实没有调用accumulate?? 不知道是怎么回事? JSONArray jsonArray = new JSONArray(); jsonArray.add(0,"person1"); jsonArray.add(1,"person2"); json.put("friend", jsonArray);//增加一个数组 System.out.println("json="+json); System.out.println("json.getString(\"user\")="+json.getString("user")); System.out.println("json.getJSONArray(\"friend\").get(0)="+json.getJSONArray("friend").get(0)); System.out.println("json.getJSONObject(\"addr\").get(\"city\")="+json.getJSONObject("addr").get("city")); }}public JSONObject element (String key, Object value) 将键/值对放到这个JSONObject对象里面。如果当前value为空(null),那么如果这个key存在的话,这个key就会移除掉。如果这
个key之前有value值,那么此方法会调用accumulate()方法。感觉这句有问题,还是没写对呢?
1 0
- jsonobject的element和accumulate
- JSONObject put,accumulate,element的区别 和 例子
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject:put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JsonObject put、element、accumulate的区别。
- JSONObject put,accumulate,element的区别
- JSONObject put,accumulate,element的区别
- JSONObject和JSONArray的使用 以及JSONObject put,accumulate,element的区别
- JSONObject和JSONArray的使用 以及JSONObject put,accumulate,element的区别
- JSONObject和JSONArray的使用 以及JSONObject put,accumulate,element的区别
- JSONObject put accumulate element 步骤区别
- 线程池的使用
- 单片机资源:时间和空间的思考
- 几种常见加密算法解析及使用
- bitmapshader 实现图片的放大镜效果
- PHP+mysql+ajax轻量级聊天室
- jsonobject的element和accumulate
- 【NOIP2016提高组复赛】换教室
- mysql 时间函数和事件
- 人工智能、机器学习、统计学和数据挖掘之间有什么区别?
- rocketMQ集群部署
- 如何用EM设置文本尺寸
- Android应对进程被杀死--Service(四) 通过JNI实现守护进程,使Service服务不被杀死
- 错误:Could not publish server configuration for Tomcat v7.0 Server at localhost.
- 填报校验定位出错单元格