0

有没有办法使用jsp和java for extjs将数组列表转换为json存储输入数据。意味着我需要从 jsp 页面和 java arraylis 获取 json 存储的数据

4

1 回答 1

0

在这里,希望这对您有所帮助...我在这里从数据库中获取状态值..

                    String response = "id,State#";
        List stateList = new ArrayList<>();

        //DB call

        for (int i = 0; i < stateList.size(); i++) {
            response += stateList.get(i).gets_code() + ",";
            response += stateList.get(i).getS_name() + "#";
        }
        StringTokenizer st = new StringTokenizer(response , "|");
        String finalMsg = null;
        String str1 = null;
        while (st.hasMoreElements()) {
            String token = st.nextToken();
            finalMsg = token;
        }
        JSONObject object = new JSONObject();
        stbuffer.append("{\"root\":[");
        String[] data = finalMsg.split("#");
        int len = data.length;
        String[] headings = data[0].split(",");
        for (int x = 1; x < len; x++) {
            String[] data1 = data[x].split(",");
            int len1 = data1.length;
            for (int y = 0; y < len1; y++) {
                object.put(headings[y], data1[y]);

            }
        stbuffer.append(object);
        stbuffer.append(",");

        }
        stbuffer.append("]}");
        String result = stbuffer.toString();
        result = result.replace(",]", "]");
于 2012-12-17T13:37:50.143 回答