实体类转json,不显示空值字段:
代码:
///
/// 转Json字符串,删除空值字段
/// ///
///
public static string ToJsonDelNull(this object obj)
{
var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
return JsonConvert.SerializeObject(obj, Newtonsoft.Json.Formatting.Indented, jsonSetting);
}