long str = 0;
JSONArray jsonArray = new JSONArray();
Map mapArray = new HashMap();
List list = new ArrayList();
List result = resultResource.getLacs();
Iterator o = result.iterator();
while (o.hasNext())
{
OcCsmCell ocCsmCell = (OcCsmCell) o.next();
Map mapObj = new HashMap();
if (ocCsmCell.getLai() == str)
{
mapObj.put("id", ocCsmCell.getLai());
mapObj.put("text", ocCsmCell.getLai());
mapObj.put("leaf", true);
mapObj.put("checked", false);
list.add(mapObj);
}
else
{
if (list.size() > 0)
{
mapArray.put("children", list);
jsonArray.add(mapArray);
}
list = new ArrayList();
mapArray = new HashMap();
str = ocCsmCell.getLai();
mapArray.put("id", ocCsmCell.getCi());
mapArray.put("text", ocCsmCell.getCi());
mapArray.put("cls", "folder");
mapArray.put("checked", false);
Map mapTemp = new HashMap();
mapTemp.put("id", ocCsmCell.getCi());
mapTemp.put("text", ocCsmCell.getCi());
mapTemp.put("leaf", true);
mapTemp.put("checked", false);
list.add(mapTemp);
}
if (!o.hasNext())
{
mapArray.put("children", list);
jsonArray.add(mapArray);
}
JSONArray jsonArray = new JSONArray();
Map mapArray = new HashMap();
List list = new ArrayList();
List result = resultResource.getLacs();
Iterator o = result.iterator();
while (o.hasNext())
{
OcCsmCell ocCsmCell = (OcCsmCell) o.next();
Map mapObj = new HashMap();
if (ocCsmCell.getLai() == str)
{
mapObj.put("id", ocCsmCell.getLai());
mapObj.put("text", ocCsmCell.getLai());
mapObj.put("leaf", true);
mapObj.put("checked", false);
list.add(mapObj);
}
else
{
if (list.size() > 0)
{
mapArray.put("children", list);
jsonArray.add(mapArray);
}
list = new ArrayList();
mapArray = new HashMap();
str = ocCsmCell.getLai();
mapArray.put("id", ocCsmCell.getCi());
mapArray.put("text", ocCsmCell.getCi());
mapArray.put("cls", "folder");
mapArray.put("checked", false);
Map mapTemp = new HashMap();
mapTemp.put("id", ocCsmCell.getCi());
mapTemp.put("text", ocCsmCell.getCi());
mapTemp.put("leaf", true);
mapTemp.put("checked", false);
list.add(mapTemp);
}
if (!o.hasNext())
{
mapArray.put("children", list);
jsonArray.add(mapArray);
}
JSON构建
本文介绍了一种使用Java处理JSON数据的方法,通过遍历查询结果并构建JSON结构来组织数据。该过程涉及多个步骤,包括初始化必要的数据结构,如JSONArray、HashMap等,并根据特定条件向这些结构中添加元素。
2580

被折叠的 条评论
为什么被折叠?



