public static JSONObject getDeptTree(List<Map<String,Object>> list,String id) throws JSONException{JSONObject json=new JSONObject();JSONArray jsons=new JSONArray();//children数组for (Map<String, Object> map : list) {String id=map.get("ID")==null ? "" : map.get("ID").toString();String pid=map.get("PID")==null ? "" : map.get("PID").toString();String name=map.get("NAME")==null ? "" : map.get("NAME").toString();String url=map.get("URL")==null ? "" : map.get("URL").toString();if(pid.equals(deptid)){jsons.put(getDeptTree(list,id));}if(deptid.equals(id)){json.put("ID",id);json.put("PID", pid);json.put("name", name);json.put("url",url);}}json.put("children", jsons);return json;}
本文出自 “随笔” 博客,请务必保留此出处http://12532790.blog.51cto.com/12522790/1969499
通过递归将list<Map<String,Object>>类型的数据转换为tree组件可识别的json数据
原文地址:http://12532790.blog.51cto.com/12522790/1969499