//第一种方法:
PropertyFilterfilter=
new
PropertyFilter(){
//过滤不需要的字段
public
boolean
apply(Objectsource,Stringname,Objectvalue){
if
(
"code"
.equals(name)||
"shengid"
.equals(name)){
return
false
;
}
true
;
}
};
SerializeWritersw=
SerializeWriter();
JSONSerializerserializer=
JSONSerializer(sw);
serializer.getPropertyFilters().add(filter);
serializer.write(cityList);
response.getWriter().write(sw.toString());
//第二种方法:
直接在里面写上需要的字段属性.
SimplePropertyPreFilterfilter=
SimplePropertyPreFilter(TTown.
class
,
"id"
"townname"
);
response.getWriter().write(JSONObject.toJSONString(townList,filter));