RouteResponse.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ARLocation.MapboxRoutes
  4. {
  5. using Vendor.SimpleJSON;
  6. [Serializable]
  7. public class RouteResponse
  8. {
  9. public string Code;
  10. public List<Route> routes;
  11. public List<Waypoint> waypoints;
  12. public override string ToString()
  13. {
  14. string result = "";
  15. result += "RouteResponse{ routes = [";
  16. foreach (var route in routes)
  17. {
  18. result += route + ", ";
  19. }
  20. result += "], waypoints = [";
  21. foreach (var w in waypoints)
  22. {
  23. result += w + ", ";
  24. }
  25. result += $"Code = {Code}, ";
  26. result += "]}";
  27. return result;
  28. }
  29. public static RouteResponse Parse(string json)
  30. {
  31. return Parse(JSON.Parse(json));
  32. }
  33. public static RouteResponse Parse(JSONNode node)
  34. {
  35. var result = new RouteResponse();
  36. result.routes = new List<Route>();
  37. result.waypoints = new List<Waypoint>();
  38. result.Code = node["code"].Value;
  39. var arr = node["routes"].AsArray;
  40. for (int i = 0; i < arr.Count; i++)
  41. {
  42. result.routes.Add(Route.Parse(arr[i]));
  43. }
  44. arr = node["waypoints"].AsArray;
  45. for (int i = 0; i < arr.Count; i++)
  46. {
  47. result.waypoints.Add(Waypoint.Parse(arr[i]));
  48. }
  49. return result;
  50. }
  51. }
  52. [Serializable]
  53. public class Waypoint
  54. {
  55. public string name;
  56. public Location location;
  57. public override string ToString()
  58. {
  59. return $"Waypoint{{ name = {name}, location = {location} }}";
  60. }
  61. public static Waypoint Parse(JSONNode node)
  62. {
  63. var result = new Waypoint();
  64. result.name = node["name"];
  65. result.location = new Location(node["location"][1], node["location"][0], 0);
  66. return result;
  67. }
  68. }
  69. }