fastjson生成json時Null屬性不顯示


Fastjson的SerializerFeature序列化屬性 --來自oschina bfleeee博客
QuoteFieldNames———-輸出key時是否使用雙引號,默認為true 
WriteMapNullValue——–是否輸出值為null的字段,默認為false 
WriteNullNumberAsZero—-數值字段如果為null,輸出為0,而非null 
WriteNullListAsEmpty—–List字段如果為null,輸出為[],而非null 
WriteNullStringAsEmpty—字符類型字段如果為null,輸出為”“,而非null 
WriteNullBooleanAsFalse–Boolean字段如果為null,輸出為false,而非null。
 
/*     根據名稱和類型查詢小班信息      */     
@RequestMapping("/getSBInfo")     
@ResponseBody     
public Object getSBInfo(@RequestParam Map map) {
        JSONObject jsonArray = null;         
        if (map != null) {             
            //縣、鄉、村名稱             
            String county = (String) map.get("county");             
            String town = (String) map.get("town");             
            String village = (String) map.get("village");             
            //類型是縣、鄉、村
            //"1"查詢鄉鎮, "2"查詢村, “3”查詢全部
            String type = (String) map.get("type");
            if (county != null && town != null && village != null) {
                //查全部
                Map mapAll = stateCountyService.getAll(county, town, village);
                String str = JSON.toJSONString(mapAll,SerializerFeature.WriteMapNullValue);
                jsonArray = JSONObject.parseObject(str);
            } else if (county != null && town != null) {
                //查村
                Map mapVillage = stateCountyService.getVillge(county, town);
                String str = JSON.toJSONString(mapVillage,SerializerFeature.WriteMapNullValue);
                jsonArray = JSONObject.parseObject(str);
            } else if (county != null) {
                //查鄉鎮
                Map mapTown = stateCountyService.getTown(county);
                String str = JSON.toJSONString(mapTown,SerializerFeature.WriteMapNullValue);
                jsonArray = JSONObject.parseObject(str);
            }
        }
        return jsonArray;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM