JsonUtil.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using LitJson;
  2. using System.Collections.Generic;
  3. namespace GFGGame
  4. {
  5. public class JsonUtil
  6. {
  7. private static Dictionary<string, object> _obj = new Dictionary<string, object>();
  8. public static string createJsonStr(params object[] args)
  9. {
  10. _obj.Clear();
  11. if(args != null)
  12. {
  13. int count = args.Length;
  14. for(int i = 0; i < count; i+=2)
  15. {
  16. _obj.Add((string)args[i], args[i+1]);
  17. }
  18. }
  19. return JsonMapper.ToJson(_obj);
  20. }
  21. public static Dictionary<string, object> createJsonDic(params object[] args)
  22. {
  23. Dictionary<string, object> dic = new Dictionary<string, object>();
  24. if(args != null)
  25. {
  26. int count = args.Length;
  27. for(int i = 0; i < count; i+=2)
  28. {
  29. dic.Add((string)args[i], args[i+1]);
  30. }
  31. }
  32. return dic;
  33. }
  34. }
  35. }