简体   繁体   中英

How to convert java arraylist to json array store data using java and jsp and extjs

is there any way to convert array list to json store input data using jsp and java for extjs. means i need to get data for json store from jsp page and java arraylis

Here you go hope this helps you... Here im getting state values from db..

                    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(",]", "]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM