json过滤掉不需要的字段

时间:2020-06-05 11:08:55   收藏:0   阅读:189

1.使用fastjson包

2.创建PropertityFilter对象

PropertyFilter filter = new PropertyFilter() {

@Override
public boolean apply(Object arg0, String filedname, Object arg2) {

//屏蔽cusId字段
if("cusId".equalsIgnoreCase(filedname)){
return false;
}

//屏蔽cusIMg字段
if("cusImg".equalsIgnoreCase(filedname)){
return false;
}
return true;
}
};

String jsonString = JSONObject.toJSONString(person,filter);

原文:https://www.cnblogs.com/chengjianJava/p/13047512.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!