json对象转换

String modules =...; //json格式的String对象
//String对象转换为JSON格式数组
JSONArray moduleArr=JSONObject.parseArray(modules);
for(int i=0;i<moduleArr.size();i++){
//获取数组中一个json对象
JSONObject moduleObj=moduleArr.getJSONObject(i);
//获取json对象的一个属性
String attrConditions=moduleObj.getString("attrConditions")
//如果属性又是一个json数组,则获取后循环处理
JSONArray specific=moduleObj.getJSONArray("specific");
JSONObject inputJson = new JSONObject();
//json对象转换为json格式的String对象
inputJson.toString();
//string转换为json对象
JSONObject json = JSONObject.parseObject(inputJson);

//map -- jsonString 

JSONObject json = new JSONObject(); 

 Map<String, Object> map = new HashMap<String, Object>();
            map.put("12", "string");
            map.put("13", "test");
            System.out.println(JSONObject.fromObject(map).toString());
原文地址:https://www.cnblogs.com/jing1617/p/7262468.html