字符串解析成easyui-tree的格式

Posted Sunnor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串解析成easyui-tree的格式相关的知识,希望对你有一定的参考价值。

传入的list:

[30 : null : null, 301503 : null : null, 301501 : null : null, 301502 : null : null, 3015 : null : null]

解析后的json:

 

 

  1 public class LeftTreeBean {
  2     public StringBuilder getTreeMenus(List lst, String contextPath) {
  3         StringBuilder model = new StringBuilder("");
  4         String RightName = "";
  5         String RightURL = "";
  6 
  7         Map rightMap = new HashMap();
  8 
  9 //        for (RightObject ro : (ArrayList) lst) {
 10         for (Object ro : lst) {
 11             ro = (RightObject)ro;
 12             String parentId = ((RightObject) ro).getParentID();
 13 
 14             if ((parentId == null) || (parentId.trim().length() == 0)
 15                     || (parentId.equalsIgnoreCase("0"))) {
 16                 parentId = "0";
 17             }
 18             if (!rightMap.containsKey(parentId)) {
 19                 rightMap.put(parentId, new ArrayList());
 20             }
 21 
 22             ((List) rightMap.get(parentId)).add(ro);
 23         }
 24 
 25         List lro = (List) rightMap.get("0");
 26 
 27         if (lro != null) {
 28             model.append("[");
 29 
 30             Map mt = ConfUtil.getMenus();
 31 
 32 //            for (RightObject ro : lro) {
 33             for (Object ro : lro) {
 34                 ro = (RightObject)ro;
 35                 RightName = (String) ((Map) mt.get(((RightObject) ro).getRightID()))
 36                         .get("RIGHTNAME");
 37                 RightURL = "";
 38 
 39                 model.append(\'{\').append("key:")
 40                         .append(JSONUtilities.quote(((RightObject) ro).getRightID()))
 41                         .append(",title:")
 42                         .append(JSONUtilities.quote(RightName));
 43 
 44                 if (rightMap.containsKey(((RightObject) ro).getRightID())) {
 45                     model.append(",isFolder:true,children:[\\n");
 46 
 47                     for (RightObject ro2 : (List) rightMap.get(ro.getRightID())) {
 48                         Map rItem = (Map) mt.get(ro2.getRightID());
 49                         if (rItem != null) {
 50                             RightName = (String) rItem.get("RIGHTNAME");
 51 
 52                             model.append("\\t{")
 53                                     .append("key:")
 54                                     .append(JSONUtilities.quote(ro2
 55                                             .getRightID())).append(",title:")
 56                                     .append(JSONUtilities.quote(RightName));
 57 
 58                             if (rightMap.containsKey(ro2.getRightID())) {
 59                                 model.append(",isFolder:true,children:[\\n");
 60 
 61                                 for (RightObject ro3 : (List) rightMap.get(ro2
 62                                         .getRightID())) {
 63                                     if (mt.containsKey(ro3.getRightID())) {
 64                                         RightName = (String) ((Map) mt.get(ro3
 65                                                 .getRightID()))
 66                                                 .get("RIGHTNAME");
 67                                         RightURL = (String) ((Map) mt.get(ro3
 68                                                 .getRightID())).get("URL");
 69                                         String BUSSFUNCID = ro3.getBussFuncID();
 70 
 71                                         String split = RightURL.indexOf("?") >= 0 ? "&"
 72                                                 : "?";
 73                                         String url = contextPath
 74                                                 + RightURL.replace(\'\\\\\', \'/\')
 75                                                 + split + "RightID="
 76                                                 + ro3.getRightID()
 77                                                 + "&_menuID="
 78                                                 + ro3.getRightID() + "&funcID="
 79                                                 + BUSSFUNCID;
 80 
 81                                         model.append("\\t\\t{")
 82                                                 .append("key:")
 83                                                 .append(JSONUtilities.quote(ro3
 84                                                         .getRightID()))
 85                                                 .append(",title:")
 86                                                 .append(JSONUtilities
 87                                                         .quote(RightName))
 88                                                 .append(",url:")
 89                                                 .append(JSONUtilities
 90                                                         .quote(url))
 91                                                 .append("},\\n");
 92                                     }
 93                                 }
 94                                 model.deleteCharAt(model.length() - 2).append(
 95                                         "\\t\\t]");
 96                             }
 97                             model.append("},\\n");
 98                         }
 99                     }
100                     model.deleteCharAt(model.length() - 2).append("\\t]");
101                 }
102                 model.append("},\\n");
103             }
104 
105             model.deleteCharAt(model.length() - 2).append(\']\');
106         }
107 
108         return model;
109     }
110 }

 

以上是关于字符串解析成easyui-tree的格式的主要内容,如果未能解决你的问题,请参考以下文章

java中把json怎么转换成数组?

java字符串格式转换成日期格式

Golang实践录:反射reflect的一些研究及代码汇总

JS中如何将JSON的字符串解析成JSON数据格式

微信小程序json数据如何处理?

片段(Java) | 机试题+算法思路+考点+代码解析 2023