首页  »   JavaScript

把java对象拼凑成json

网友分享于:2013-12-29  浏览:4次
把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);

相关解决方案

最新解决方案