zoukankan      html  css  js  c++  java
  • JSON.toJSONString(Object object,SerializerFeature...features)详解

    D

    package myProject;
    
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONObject;
    import com.alibaba.fastjson.serializer.SerializerFeature;
    
    public class FastJsonTest {
        
        private int a;
        private BigDecimal b;
        private String c;
        private List<Student> list;
        
    
        public String getC() {
            return c;
        }
    
    
        public void setC(String c) {
            this.c = c;
        }
    
    
        public int getA() {
            return a;
        }
    
    
        public void setA(int a) {
            this.a = a;
        }
    
    
        public BigDecimal getB() {
            return b;
        }
    
    
        public void setB(BigDecimal b) {
            this.b = b;
        }
    
    
        public List<Student> getList() {
            return list;
        }
    
    
        public void setList(List<Student> list) {
            this.list = list;
        }
    
    
        public static void main(String[] args) {
            FastJsonTest f=new FastJsonTest();
            String json1=JSON.toJSONString(f);
            String json2=JSON.toJSONString(f,SerializerFeature.WriteMapNullValue,SerializerFeature.WriteNullListAsEmpty,SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteNullNumberAsZero);
            System.out.println("json1"+json1);
            System.out.println("json2"+json2);
            
        }
    }

    输出结果为:

    json1{"a":0}
    json2{"a":0,"b":0,"c":"","list":[]}

    可见,BigDecimal类型,String类型,List类型在不添加对应参数,都不会显示出来。

  • 相关阅读:
    团队冲刺阶段二(八)
    团队项目事后诸葛亮会议
    团队冲刺阶段二(七)
    团队冲刺阶段二(六)
    团队冲刺阶段二(五)
    团队冲刺阶段二(四)
    HTML5 CSS3
    浮动和渐变色,定位position,元素的层叠顺序
    css盒模型。边框和内外边距
    标签分类与元素转换
  • 原文地址:https://www.cnblogs.com/BonnieWss/p/9268338.html
Copyright © 2011-2022 走看看