首页 > 其他分享 >.Net Core WebAPI 序列化时忽略空值字段

.Net Core WebAPI 序列化时忽略空值字段

时间:2023-02-17 08:33:04浏览次数:51  
标签:WebAPI Core WhenWritingNull set string get 序列化 public

特定实体

    public class APIResponseModel
    {
        /// <summary>
        /// 返回标识,200:成功,其它:失败
        /// </summary>
        public string Code { get; set; } = "201";
        /// <summary>
        /// 返回描述
        /// </summary>
        public string Msg { get; set; }
        /// <summary>
        /// 返回数据(DES加密后)
        /// </summary>
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string Data { get; set; }
    }

全局

builder.Services.AddControllers().AddJsonOptions(options => {
                options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
            }); 

 

标签:WebAPI,Core,WhenWritingNull,set,string,get,序列化,public
From: https://www.cnblogs.com/icejd/p/17128883.html

相关文章