码迷,mamicode.com
首页 > Web开发 > 详细

JsonHelper

时间:2017-09-22 19:03:10      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:blog   ring   serial   span   new   eof   ret   att   and   

 1     static class JsonHelper
 2     {
 3         public static string ToJson(this object obj)
 4         {
 5             var str = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings
 6             {
 7                 NullValueHandling = NullValueHandling.Ignore,
 8                 DateFormatString = "yyyy-MM-dd HH:mm:ss",
 9                 ReferenceLoopHandling = ReferenceLoopHandling.Ignore//循环引用
10             });
11             return str;
12         }
13 
14         public static T FromJson<T>(this string json) where T : class
15         {
16             return JsonConvert.DeserializeObject(json, typeof(T), new IsoDateTimeConverter
17             {
18                 DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
19             }) as T;
20         }
21     }

 

JsonHelper

标签:blog   ring   serial   span   new   eof   ret   att   and   

原文地址:http://www.cnblogs.com/jonney-wang/p/7576065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!