转Json字符串为空不序列化

转Json字符串为空不序列化

原文:Newtonsoft.Json 转Json字符串为空不序列化

版权声明:本文为博主原创文章,遵循 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






01-15 10:08