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;
        }
  • 相关阅读:
    java设计模式之代理模式 ,以及和java 回调机制的区别
    oracle 安装,启动 ,plsql 连接
    jsp 访问文件夹中的图片,tomcat配置虚拟目录
    最实用解决tomcat startup.bat 一闪而过
    oracle 创建表
    java debug源码完整版
    node.js事件轮询(1)
    markdown命令语法
    mac常用的命令
    node + nginx + mongo搭建负载均衡
  • 原文地址:https://www.cnblogs.com/Jane460334861/p/10039241.html
Copyright © 2011-2022 走看看