【JAVA-工具类】response写出json

来源:互联网 发布:debian centos 读音 编辑:程序博客网 时间:2024/04/27 12:44
public void convert2json(Object obj) {        String json = JSONObject.toJSONString(obj);        HttpServletResponse response = getResponse();        response.setContentType("application/json;charset=utf-8");        PrintWriter out = null;        try {            out = response.getWriter();            out.write(json);        } catch (IOException e) {            logger.error("BaseAction::writerJson catch exception:",e);        } finally {            if (out != null)                out.close();        }    }           public void writerJson(Object obj) {        String json = JSONObject.toJSONString(obj);        HttpServletResponse response = getResponse();        response.setContentType("application/json;charset=utf-8");        PrintWriter out = null;        try {            out = response.getWriter();            out.write(json);        } catch (IOException e) {            logger.error("BaseAction::writerJson catch exception:",e);        } finally {            if (out != null)                out.close();        }    }    public void writerArrayJson(Object obj) {        String json = JSONObject.toJSONString(obj);        HttpServletResponse response = getResponse();        response.setContentType("application/json;charset=utf-8");        PrintWriter out = null;        try {            out = response.getWriter();            out.write(json);        } catch (IOException e) {            logger.error("BaseAction::writerJson catch exception:",e);        } finally {            if (out != null)                out.close();        }    }


0 0
原创粉丝点击