首页 > 其他 > 详细

自己用的各种工具类(不喜勿喷)

时间:2014-12-19 12:00:59      阅读:170      评论:0      收藏:0      [点我收藏+]

1:List转Json

public static String list2JsonArray(List list) {
        StringBuffer str = new StringBuffer("[");
        if (list != null && list.size() > 0) {
            int len = list.size();
            Object map = null;

            for (int i = 0; i < len; i++) {
                map = list.get(i);
                if (i > 0) {
                    str.append(",");
                }
                str.append(JSONUtil.object2json(map));
            }
        }
        str.append("]");
        return str.toString();
    }

2:ajax向前端返回json字符串

//向前端返回json字符串
    public void outString(String json) {
        PrintWriter print = null;
        try {
            HttpServletResponse response;
            response = this.getResponse();
            response.setContentType("text/json;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Pargma", "no-cache");
            response.setDateHeader("Expires", 0);
            print = this.getResponse().getWriter();
            print.write(json);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

先吃饭去了 其他的慢慢补充  嘿嘿

自己用的各种工具类(不喜勿喷)

原文:http://www.cnblogs.com/dnxf/p/4173482.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!