返回json数据中属性为null不参与序列化

来源:互联网 发布:js如何显示表单内容 编辑:程序博客网 时间:2024/06/10 03:29

在工作中遇到一个需求:返回json中的数据为null的属性不显示,即不参与序列化,此时需要进行处理

String  json=JSONObject.toJSONString(new QueryResult ("0","success",videoList),SerializerFeature.WriteNullListAsEmpty)// 设置字符集        response.setCharacterEncoding("UTF-8");        response.setHeader("Content-Type", "text/html;charset=UTF-8");        try {            PrintWriter writer = response.getWriter();            writer.write(json);        } catch (IOException e) {            LOG.error("写入Response异常", e);        }
阅读全文
0 0
原创粉丝点击