jsonobject 遍历 org.json.JSONObject
来源:互联网 发布:白金数据 电影百度云 编辑:程序博客网 时间:2024/05/01 12:27
[html] view plain copy
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- 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();
- }
- }
- {"groups":[{"exp":"AB=ab","count":110,"name":"AB","value":"ab"},{"exp":"AB=ab2","count":115,"name":"AB","value":"ab2"},{"exp":"AB=ab3","count":210,"name":"AB","value":"ab3"},{"exp":"TI=aa1","count":10,"name":"TI","value":"aa1"},{"exp":"TI=aa2","count":15,"name":"TI","value":"aa2"},{"exp":"TI=aa3","count":20,"name":"TI","value":"aa3"}]}
0 0
- jsonobject 遍历 org.json.JSONObject
- jsonobject 遍历 org.json.JSONObject
- jsonobject 遍历 org.json.JSONObject
- jsonobject 遍历 org.json.JSONObject
- org.json.simple JSONArray JSONObject
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别。
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别。
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
- org.json.JSONObject中list转json
- 关于Json解析(org.json.JSONObject)
- 遍历JSONObject
- 方维一元夺宝1.73:新增预选包尾+直购功能+机器人晒单+极速专区+手机版晒单+新手红包
- listview gridview 之ChoiceMode
- eclipse安装Activiti Designer插件
- 在ubuntu 14.04搭建React Native for Android开发环境
- 【OTT】OTT Media Grinder (OTT TV 质量评价设备)
- jsonobject 遍历 org.json.JSONObject
- 需要时刻记住的话
- 链表,冒泡,并查集
- log4j使用
- qemu源码架构
- C++模版使用用例
- Linux安装svn服务端
- 查看挂载阵列卡下的磁盘SMART
- JQuery日期插件datepicker的使用