特定实体
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