将list转为json字符串

//确保JSP和servlet的编码方式一致
resp.setContentType("text/html;charset=GBK");
List<String> jymdList = new ArrayList<String>();
PrintWriter out = null;
    try {
        //从数据库中取得List
        jymdList = efileViewUiService.getLymd();
        //简单粗暴,对于Map这句也适用
        String json = JSON.toJSONString(jymdList);
        //取得流向JSP传递数据    
        PrintWriter out = resp.getWriter();
        out.print(json);
    } catch (BaseException e) {
        e.printStackTrace();
    } finally{
        out.close();      
    }
            
复制代码
原文地址:https://www.cnblogs.com/panxuejun/p/6148592.html