fastjson忽略属性JSON⾃定义序列化(过滤掉不想要的属性)    这⾥只讲JSON-LIB和FastJson两种Json⼯具的序列化过滤问题
⽐如,我想过滤的属性有id,和name,先演⽰json-lib
1.Json-Lib
//通过json-lib将数据序列化为json格式
JsonConfig jsonConfig = new JsonConfig();
//进⾏过滤
jsonConfig. setExcludes(new String[]{"id","name"});
//转化成json数据格式
JSONObject jsonObject = new JSONObject();
String json = String();
//将json数据通过流写⼊到客户端
HttpServletResponse response = Response();
response.setContentType("text/json;charset=UTF-8");
2.FastJson
//使⽤fastjson,过滤
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
//过滤字段
Set<String> set = filter. getExcludes();
set.add("id");
set.add("name");
String jsonString = JSONString(pageBean,filter);
/
/处理中⽂乱码问题!
HttpServletResponse response = Response();
response.setContentType("text/json;charset=UTF-8");
第⼀次写blog,知识的积累,贵在点滴!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。