欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

把java对象拼接成json JavajsonJ#浏览器 

程序员文章站 2024-03-24 08:46:22
...
else
                {
                    //根据用户id,位置区查询所有的小区
                    List<AcceptCI> listCi = businessService.queryAllCIByAccountIdAndAcceptLai(1, list.get(i));
                    strLac.append("{id:'" + (idFlag++) + "',text:'" + parent + "',checked:false");
                    //如果位置区下面有小区
                    if (listCi.size() > 0)
                    {
                        strLac.append(",children: [");
                        for (int j = 0; j < listCi.size(); j++)
                        {
                            AcceptCI node = listCi.get(j);
                            //是否是最后一个小区
                            if ((listCi.size() - 1) > j)
                            {
                                strLac.append("{id:'" + node.getAcceptCi() + "',text:'" + node.getAcceptCi()
                                    + "',checked:false,leaf:true},");
                            }
                            else
                            {
                                strLac.append("{id:'" + node.getAcceptCi() + "',text:'" + node.getAcceptCi()
                                    + "',checked:false,leaf:true}");
                            }
                        }
                        //是最后一个位置区,且位置区下有小区
                        strLac.append("]}");
                    }
                    else
                    {
                        //是最后一个位置区.但其下没有小区
                        strLac.append("}");
                    }
                }
            }
            strLac.append("]");
            System.out.println("_______" + strLac);
            //对浏览器的请求作出响应
            response.getWriter().print(strLac);