分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

通过递归将list<Map<String,Object>>类型的数据转换为tree组件可识别的json数据

发布时间:2023-09-06 01:14责任编辑:顾先生关键词:jsjson递归组件
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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved