前台數據傳遞到后台轉json
1、普通格式轉換成對象
String data=request.getParameter("data"); //單數據的時候轉換方式 JSONObject json= JSONObject.fromObject(data); Tree tree = (Tree)JSONObject.toBean(json, Tree.class);
2、Tree格式(多數據)轉成對象
HashMap mapClass=new HashMap(); mapClass.put("children", Tree.class); //children屬性是一個list集合 Tree tree = (Tree)JSONObject.toBean(json, Tree.class,mapClass); //Tree是對應的實體對象
3、后台將前台傳來的一系列的數據轉換為list集合
String data = eac.getParamValue("data"); String str = data.replaceAll("\"", "").replaceAll("\\\\", "\""); //多數據轉json的格式 JSONArray json = JSONArray.fromObject(str); //將json轉為list List<SkdDcdaContractProblemPo> list = (List<SkdDcdaContractProblemPo>) JSONArray.toCollection(json,SkdDcdaContractProblemPo.class);