public class BigDecimalValueFilter implements ValueFilter { @Override public Object process(Object o, String name, Object value) { //o是待轉換的對象,name是字段名,value是字段值 if (null != value && value instanceof BigDecimal) { return ((BigDecimal) value).setScale( 2 ).toString(); } return value; } }
JSONObject.toJSONString(object, bigDecimalValueFilter,SerializerFeature.WriteNullNumberAsZero);