java后台轉json、轉對象、轉list集合


前台數據傳遞到后台轉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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM