public static void main(String[] args) { String str = "{'TI':[{'value':'aa1','count':10},{'value':'aa2','count':15},{'value':'aa3','count':20}]," + "'AB':[{'value':'ab','count':110},{'value':'ab2','count':115},{'value':'ab3','count':210}]}"; JSONArray newArray = new JSONArray(); JSONObject newJson = new JSONObject(); try { JSONObject obj = new JSONObject(str); Iterator it = obj.keys(); while (it.hasNext()) { String key = (String) it.next(); String value = obj.getString(key); JSONArray array = obj.getJSONArray(key); for(int i=0;i<array.length();i++){ JSONObject jsonobject = array.getJSONObject(i); jsonobject.put("name", key); jsonobject.put("exp", key+"="+jsonobject.getString("value")); newArray.put(jsonobject); } } newJson.put("groups",newArray); System.out.println(newJson); } catch (JSONException e) { e.printStackTrace(); } }
相关推荐
org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包 org.json.JSONObject引用依赖包
org.json.JSONObject的6个jar包 commons-beanutils;commons-collections;commons-lang;commons-logging;ezmorph;json-lib
JSONObject JSONArray JavaBean和json数据的转换等,都可以使用。
java开发中需要jsonObject,jsonArray需要用到6个jar包,net.sf.json.JSONObject commons-beanutils-1.7.0.jar commons-collections-3.1.jar commons-lang-2.5.jar commons-logging.jar ezmorph-1.0.3.jar json-lib-...
net.sf.json.JSONObject需要的jar包 -- net.sf.json.JSONObject需要的jar包
net.sf.json.JSONObject相关依赖架包,导入项目后,JSONObject.fromObject()方法就可以使用了
net.sf.json.JSONObject所需要的jar包 commons-beanutils-1.9.3.jar commons-collections-3.2.2 commons-lang-2.6 commons-logging-1.2 ezmorph-1.0.6 json-lib-2.4-jdk15
解决net.sf.json.JSONObject 解决net.sf.json.JSONObject
net.sf.json.JSONObject相关jar包
org.json.JSONObect的一个jar包org.json.JSONObect的一个jar包
Java的net.sf.json.JSONObject , 发现Maven仓库找不到, 特意上传供大家分享
net.sf.json.JSONArray等JSON类所需要的jar包组合。包括JSONObject等
NULL 博文链接:https://bijian1013.iteye.com/blog/2310861
commons-beanutils-1.9.3.jar、commons-collections-3.2.2.jar、commons-lang-2.6.jar、commons-logging-1.2.jar、ezmorph-1.0.6.jar、json-lib-2.4-jdk15.jar
1.解析json字符串 2.将json字符串转换为java对象 3.将java对象转换为json字符串
JSONObject、JSONArray需要的jar包,需要的可以直接联系
NULL 博文链接:https://suko.iteye.com/blog/2187798
文档附件用于阐述net.sf.json.JSONObject对象的使用,详细讲述了存储和检索,对于Java Web开发和Spring-MVC的很有帮助