AllTool.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class AllTool : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 获取当前时间戳
  10. /// </summary>
  11. /// <returns></returns>
  12. public static long GetTimeStamp()
  13. {
  14. return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
  15. }
  16. /// <summary>
  17. /// Json 解析
  18. /// </summary>
  19. /// <param name="message"></param>
  20. /// <returns></returns>
  21. public static Root ToJsonData(String message)
  22. {
  23. try
  24. {
  25. JsonData json = JsonMapper.ToObject(message);
  26. JsonData data = json["projectinfo"]["navLines"];
  27. message = data.ToJson();
  28. //message = message.Substring(1, message.Length - 1);
  29. message = "{\"navLines\":" + message + "}";
  30. Debug.Log(message);
  31. Root root = JsonMapper.ToObject<Root>(message);
  32. Debug.Log(root.navLines.Count);
  33. return root;
  34. }
  35. catch (Exception)
  36. {
  37. Debug.LogError("Json 传入格式不正确 无法解析");
  38. return null;
  39. }
  40. }
  41. }