json过滤不需要的字段

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.PropertyFilter;

/*导包不要导错了*/  


JsonConfig config1 = new JsonConfig(); final String[] array = new String[] { "createObjSql", "deleteObjSql", "queryObjSql", "updateObjSql", "createtimeBegin", "createtimeEnd", "keyPropertyName", "keyColumnName", "createtime" ,"tableName","queryOrderBy","queryOrderDirection","primaryId","p1", "p2","p3","p4"}; config1.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object source, String name, Object value) { for (String propName : array) { if (name.equals(propName)) { return true; } } return false; } }); String result = JSONObject.fromObject(map, config1).toString();
原文地址:https://www.cnblogs.com/lxk233/p/9896772.html