123456789101112131415161718192021222324252627 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Newtonsoft.Json;
- using System.IO;
- namespace Bowin.Common.JSON
- {
- public static class ConvertJsonToObject
- {
- public static T ToObject<T>(this string json)
- {
- return JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local, NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore });
- }
- public static string ToJson(this object obj)
- {
- return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local, NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore });
- }
- public static T Map<T>(this object obj) where T : class
- {
- return obj.ToJson().ToObject<T>();
- }
- }
- }
|