ConvertJsonToObject.cs 885 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web.Script.Serialization;
  6. using Newtonsoft.Json;
  7. using System.IO;
  8. namespace Bowin.Common.JSON
  9. {
  10. public static class ConvertJsonToObject
  11. {
  12. public static T JsonToObject<T>(this string json)
  13. {
  14. return JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local, NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore });
  15. }
  16. public static string ToJson(this object obj)
  17. {
  18. return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Local, NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore });
  19. }
  20. }
  21. }