码迷,mamicode.com
首页 > Web开发 > 详细

JSONObject遍历获取键值方法合并两个JSONObject

时间:2017-08-18 11:00:53      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:color   val   object   string   接收   str   sonar   ring   iterator   

JSONObject obj1= new JSONObject();
        try {
            obj1.put("obj1_data", obj1_data);
            
            if (null != obj2) {//obj2已有json数据
                Iterator<String> sIterator = obj2.keys();
                while (sIterator.hasNext()) {
                    // 获得key
                    String key = sIterator.next();
                    // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
                    String value = obj2.getString(key);
                    obj1.put(key, value);
                }
//此时obj1中已经包含了自己本身和obj2的所有数据
            }

这是org.json包下的JSONObject

JSONObject遍历获取键值方法合并两个JSONObject

标签:color   val   object   string   接收   str   sonar   ring   iterator   

原文地址:http://www.cnblogs.com/Sharley/p/7387893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!