JsonHelper.cs 703 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using LitJson;
  3. using Model;
  4. namespace Hotfix
  5. {
  6. public static class JsonHelper
  7. {
  8. public static string ToJson(object obj)
  9. {
  10. return JsonMapper.ToJson(obj);
  11. }
  12. public static T FromJson<T>(string str)
  13. {
  14. return JsonMapper.ToObject<T>(str);
  15. }
  16. public static object FromJson(Type type, string str)
  17. {
  18. return JsonMapper.ToObject(type, str);
  19. }
  20. public static T FromJson<T>(byte[] bytes, int index, int count)
  21. {
  22. string str = bytes.ToStr();
  23. return JsonMapper.ToObject<T>(str);
  24. }
  25. public static object FromJson(Type type, byte[] bytes, int index, int count)
  26. {
  27. string str = bytes.ToStr(index, count);
  28. return JsonMapper.ToObject(type, str);
  29. }
  30. }
  31. }