首页 > Web开发 > 详细

JsonHelper

时间:2017-09-22 18:23:49      阅读:226      评论:0      收藏:0      [点我收藏+]
 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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!