日期:2014-05-16  浏览次数:20536 次

把java对象拼接成json
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);