传入的list:
[30 : null : null, 301503 : null : null, 301501 : null : null, 301502 : null : null, 3015 : null : null]
解析后的json:
public class LeftTreeBean {
public StringBuilder getTreeMenus(List lst, String contextPath) {
StringBuilder model = new StringBuilder("");
String RightName = "";
String RightURL = ""; Map rightMap = new HashMap(); // for (RightObject ro : (ArrayList) lst) {
for (Object ro : lst) {
ro = (RightObject)ro;
String parentId = ((RightObject) ro).getParentID(); if ((parentId == null) || (parentId.trim().length() == 0)
|| (parentId.equalsIgnoreCase("0"))) {
parentId = "0";
}
if (!rightMap.containsKey(parentId)) {
rightMap.put(parentId, new ArrayList());
} ((List) rightMap.get(parentId)).add(ro);
} List lro = (List) rightMap.get("0"); if (lro != null) {
model.append("["); Map mt = ConfUtil.getMenus(); // for (RightObject ro : lro) {
for (Object ro : lro) {
ro = (RightObject)ro;
RightName = (String) ((Map) mt.get(((RightObject) ro).getRightID()))
.get("RIGHTNAME");
RightURL = ""; model.append('{').append("key:")
.append(JSONUtilities.quote(((RightObject) ro).getRightID()))
.append(",title:")
.append(JSONUtilities.quote(RightName)); if (rightMap.containsKey(((RightObject) ro).getRightID())) {
model.append(",isFolder:true,children:[\n"); for (RightObject ro2 : (List) rightMap.get(ro.getRightID())) {
Map rItem = (Map) mt.get(ro2.getRightID());
if (rItem != null) {
RightName = (String) rItem.get("RIGHTNAME"); model.append("\t{")
.append("key:")
.append(JSONUtilities.quote(ro2
.getRightID())).append(",title:")
.append(JSONUtilities.quote(RightName)); if (rightMap.containsKey(ro2.getRightID())) {
model.append(",isFolder:true,children:[\n"); for (RightObject ro3 : (List) rightMap.get(ro2
.getRightID())) {
if (mt.containsKey(ro3.getRightID())) {
RightName = (String) ((Map) mt.get(ro3
.getRightID()))
.get("RIGHTNAME");
RightURL = (String) ((Map) mt.get(ro3
.getRightID())).get("URL");
String BUSSFUNCID = ro3.getBussFuncID(); String split = RightURL.indexOf("?") >= 0 ? "&"
: "?";
String url = contextPath
+ RightURL.replace('\\', '/')
+ split + "RightID="
+ ro3.getRightID()
+ "&_menuID="
+ ro3.getRightID() + "&funcID="
+ BUSSFUNCID; model.append("\t\t{")
.append("key:")
.append(JSONUtilities.quote(ro3
.getRightID()))
.append(",title:")
.append(JSONUtilities
.quote(RightName))
.append(",url:")
.append(JSONUtilities
.quote(url))
.append("},\n");
}
}
model.deleteCharAt(model.length() - 2).append(
"\t\t]");
}
model.append("},\n");
}
}
model.deleteCharAt(model.length() - 2).append("\t]");
}
model.append("},\n");
} model.deleteCharAt(model.length() - 2).append(']');
} return model;
}
}