public Result queryPageList(HttpServletRequest req) {
List<TyzcData> records = tyzcDataService.getList(req.getParameter("adId"));
JSONArray array = (JSONArray)JSONArray.toJSON(records);
JSONArray results = new JSONArray();
for (int i = 0; i < array.size(); i++) {
JSONObject json = (JSONObject)array.get(i);
if(json.get("tpid")==null){
results.add(getJson(json,array));
}
}
return Result.OK(results);
}
/**
*
* @param jsonObject 当前节点
* @param array json数组
*/
public JSONObject getJson(JSONObject jsonObject,JSONArray array){
JSONArray children = (JSONArray)jsonObject.get("children");
if(children==null){
children=new JSONArray();
jsonObject.put("children",children);
}
for (int i = 0; i < array.size(); i++) {
JSONObject json = (JSONObject)array.get(i);
if(jsonObject.get("tid").equals(json.get("tpid"))){
children.add(json);
getJson(json,array);
}
}
if(children.size()==0){
jsonObject.remove("children");
}
return jsonObject;
}
List对象转Treejson,树形数据转换
最新推荐文章于 2025-05-26 16:38:55 发布