Json序列化中null字段说明

一、数据json的序列化实例

1.DBNull.Value 序列化结果为 null

2.在类中的可空字段和引用类型的属性,如果没有指定对象的情况下 序列化结果为空

//特别说明: DBNull.Value 序列化结果为 null
string result = ser.Serialize(new { nage = "张三", age = DBNull.Value });
Console.WriteLine(result); //{"nage":"张三","age":null}

//特别说明:在类中的可空字段和引用类型的属性,如果没有指定对象的情况下 序列化结果为空
Student stu = new Student();
Console.WriteLine(ser.Serialize(stu)); // {"ID":0,"Age":null,"Name":null,"Instance":null}
Model类:

public class Student
{
    public int ID { get; set; }
    public int? Age { get; set; }
    public string Name { get; set; }
    public Student Instance { get; set; }
}

二、json 结果Null值在Echarts中的使用:

1.在指定数据的时候,如果指定为null,或者undefined 则对应的线段不会画出

HTML:

<script src="../Js/echarts3/echarts.min.js"></script>
<style>
    body, html {
        padding: 0px;
        margin: 0px;
        width: 100%;
        height: 100%;
    }
</style>
<div id="container" style="height:100%;"></div>
JS:

/*
* 特别说明:在指定数据的时候,如果指定为null,或者undefined 则对应的线段不会画出
*/
var option = {
    title: {
        text: '堆叠区域图',
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data: ['邮件销量']
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    grid: {
        left: '3%',
        right: '8%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [
        {
            type: 'category',
            boundaryGap: false, //坐标轴的两边是否留白
            position: 'top',
            splitLine: {
                show: true
            },
            name: '本星期',
            nameLocation: 'end',
            // data: ['周一']
            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        }
    ],
    yAxis: [
        {
            type: 'value'
        }
    ],
    series: [
        {
            name: '邮件营销',
            type: 'line',
            lineStyle: {
                normal: {
                    width: 1,
                    color: 'yellow'
                }
            },
            areaStyle: { normal: {} },
            data: [120, 132, 120, 100, undefined, undefined, undefined]
        }
    ]
}
var myChart = echarts.init(document.getElementById('container'));
myChart.setOption(option);
window.onresize = function () {
    myChart.resize();
}

显示结果:





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值