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

把java对象拼接成json Javajson 

程序员文章站 2024-03-24 08:54:52
...
List<AcceptOpc> list = businessService.queryAllOpcByAccountId(1);
            StringBuffer strOpc = new StringBuffer();
            strOpc.append("[{id:'qx',text: '全选',leaf: true,checked: false},");
            for (int i = 0; i < list.size(); i++)
            {
                AcceptOpc opc = list.get(i);
                if ((list.size() - 1) > i)
                {
                    strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'},");
                }
                else
                {
                    strOpc.append("{id:" + opc.getId() + ",leaf:true,checked:false,text:'" + opc.getText() + "'}");
                }
            }
            strOpc.append("]");
            response.getWriter().print(strOpc);
相关标签: Java json