JsonExtension.cs 516 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Newtonsoft.Json;
  7. namespace CP.Common
  8. {
  9. public static class JsonExtension
  10. {
  11. public static T JsonToT<T>(this string data)
  12. where T : class, new()
  13. {
  14. return JsonConvert.DeserializeObject<T>(data);
  15. }
  16. public static string TryToJson(this object data)
  17. {
  18. return JsonConvert.SerializeObject(data);
  19. }
  20. }
  21. }