版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
Newtonsoft.Json 转Json字符串为空不序列化
static JsonSerializerSettings mJsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
public static string ObjectToJson(object obj)
{
return JsonConvert.SerializeObject(obj, Formatting.Indented, mJsonSettings);
}
如果想返回的json 没有 \r\n
改成:
static JsonSerializerSettings mJsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
public static string ObjectToJson(object obj)
{
return JsonConvert.SerializeObject(obj, Formatting.None, mJsonSettings);
}
Formatting.Indented
改为:Formatting.None