json Tree字符串 转化为List



/***
* json数组 递归 返回List<ModelMenu>
* @param jsonArray
* @return
*/
public static ArrayList<DreamBo> convertModelMenu(JSONArray jsonArray) {
ArrayList<DreamBo> dreamBos = new ArrayList<>();

for (int i = 0; i < jsonArray.size(); i++) {
DreamBo dreamBo = new DreamBo();
JSONObject m = jsonArray.getJSONObject(i);
if(m.has("children")){
String child = m.getString("children");
if(!StringUtils.isEmpty(child) && !child.equals("null")) {
JSONArray jsonobject = JSONArray.fromObject(child);
dreamBos.addAll(ProjectContractController.convertModelMenu(jsonobject));
}
}
dreamBo.setId(m.getString("id"));
dreamBo.setpId(m.getString("pId"));
dreamBo.setTitle(m.getString("title"));
dreamBo.setSax(m.getInt("sax"));
dreamBos.add(dreamBo);
}
return dreamBos;
}

JSONArray jsonobject = JSONArray.fromObject(listData);
List<DreamBo> aList = ProjectContractController.convertModelMenu(jsonobject);

上一篇:2021-02-21


下一篇:JsonArray