请通过浏览器功能收藏网页

JSON输出 通用函数编写 语言问题

发布时间:2018-10-09 17:22:34  作者:本站编辑  来源:本站原创  浏览次数:
我有话说 | 分享 |
www.javainfo.com.cn 上干货 欢迎收藏


目前主力的B/S架构的系统,大部分都采用接口模式提供数据,交互的语言一般采用JSON字符格式, JSON格式输出到客户端的通用函数 整理如下


public static void printJsonStr(String jsonStr, HttpServletResponse response) {
        // 设置格式为text/json
        response.setContentType("text/json");
        // 设置字符集为'UTF-8'
        response.setCharacterEncoding("UTF-8");
        try {
            PrintWriter pw = response.getWriter();
            pw.write(jsonStr);
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


如有疑问 请留言 欢迎提供建议

评论已有 0