StringBuffer jsonmenu = new StringBuffer();
int bzw=0;//标志位
ycWeixinMenu = weixinManager.getWeixinMenuBySubmenu();//查询父类列表
List list=ycWeixinMenu;
jsonmenu.append("{\"button\":[").append("");
for (YouchuanWeixinMenu yc:list) {//父类列表循环
if(bzw==0){//判断是否第一个父类按钮结束
bzw=1;
}else{
jsonmenu.append(",");
}
List subList = weixinManager.getWeixinMenuByMenu(yc.getName());//根据父类条件查询该父类的子类列表
if(subList.size()!=0){//判断是否有子按钮
jsonmenu.append("{\"name\":\"").append(yc.getName()).append("\"");
jsonmenu.append(",\"sub_button\":[");
int i=0;
for (YouchuanWeixinMenu obj:subList) {//遍历子类
if(i!=0){//判断是否第一个子类按钮结束
jsonmenu.append("},");
}else{
i=1;
}
jsonmenu.append("{\"type\":\"").append(obj.getType()).append("\"");
jsonmenu.append(",\"name\":\"").append(obj.getSubmenu()).append("\"");
jsonmenu.append(",\"key\":\"").append(obj.getWeixinkey()).append("\"");
if(type.equals("view")){//判断view类型是url为必须值,其他默认不写
jsonmenu.append(",\"url\"").append(obj.getWeixinurl()).append("\"");
}
}
jsonmenu.append("}]}");
}else{
jsonmenu.append("{\"name\":\"").append(yc.getName()).append("\"");
jsonmenu.append(",\"key\":\"").append(yc.getWeixinkey()).append("\"");
if(type.equals("view")){
jsonmenu.append(",\"url\"").append(yc.getWeixinurl()).append("\"");
}
jsonmenu.append(",\"type\":\"").append(yc.getType()).append("\"}");
}
}
jsonmenu.append("]}");
// 创建菜单
String s = jsonmenu.toString();