Convert jsonarray to List<jsonObject>

It is convenient for front-end analysis and needs to be converted. The net.sf.json package is selected here.

        //Get the logistics entity
        JSONObject jc = JSONObject.fromObject(resultTrace);
        JSONArray jd = jc.getJSONArray("Traces");
        List<JSONObject> list = new ArrayList<JSONObject>();
        if(jd.size()>0){
            for(int i=0;i<jd.size();i++){
                Map<String, Object> map = new HashMap<String, Object>();
                JSONObject jsonObject = jd.getJSONObject(i);
                String acceptTime = (String) jsonObject.get("AcceptTime");
                String acceptStation = (String) jsonObject.get("AcceptStation");
                map.put("acceptTime", acceptTime);
                map.put("acceptStation", acceptStation);
                list.add(JSONObject.fromObject(map));
            }
        }
        return list;

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326614360&siteId=291194637