zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    html的输出&,空格,大小于号
    html如何修改hr水平直线的粗细
    LODOP指定window默认打印机和临时默认打印机
    微软面试题: 找出二叉树上任意两个结点的最近共同父结点。
    说说自己对hibernate一级、二级、查询、缓存的理解。
    MySql中添加用户,新建数据库,用户授权,删除用户,修改密码
    修改MySQL的默认密码的四种小方法
    java中Scanner的nextLine()和next()的区别
    JAVA中String字符串比较equals()和equalsIgnoreCase()的区别
    HashMap与HashTable的区别
  • 原文地址:https://www.cnblogs.com/Jane460334861/p/10039241.html
Copyright © 2011-2022 走看看