2011-11-06 38 views

回答

0

這是一個基於Filtering Properties in JSON Advanced Features示例代碼的代碼片段,可能有用。

PropertyFilter pf = new PropertyFilter(){ 
    public boolean apply(Object source, String name, Object value) { 
     if(value != null && Number.class.isAssignableFrom(value.getClass())){ 
     return true; 
     } 
     return false; 
    } 
}; 

PrimitiveBean bean = new PrimitiveBean(); 
JsonConfig jsonConfig = new JsonConfig(); 
jsonConfig.setJsonPropertyFilter(pf); 
JSONObject json = JSONObject.fromObject(bean, jsonConfig); 

序列化的bean之前成JSON對象......如果這是你的運行時間是什麼意思你可以設置不同功能的JSON配置。

相關問題