反序列化 RouteXL 响应 Java 使用 Gson 困难作为 RouteXL Returns 多个对象而不是数组
Deserialising RouteXL Response In Java using Gson Difficult as RouteXL Returns Multiple Objects Rather Than Array
我正在尝试使用 Java
& GSON
反序列化来自 RouteXL 的响应,但是,路由作为单独的对象返回,而不是一个很痛苦的数组。有谁知道反序列化来自 RouteXL API1
的响应的简单方法?可悲的是 API2 也是如此。
Json 响应:
{
"id": "xJFPS2Z3",
"count": 4,
"feasible": true,
"route": {
"0": {
"name": "11 Main Street",
"arrival": 0,
"distance": 0
},
"1": {
"name": "19 Slate Road",
"arrival": 10,
"distance": 9.3
},
"2": {
"name": "234 Woodland Road",
"arrival": 18,
"distance": 14.5
},
"3": {
"name": "15 Great Eastern Road",
"arrival": 29,
"distance": 26.4
}
}
}
这几乎就像你需要创建一个像这样的 class 来保存所有回复:
public class Route {
private Waypoint 1;
private Waypoint 2;
private Waypoint 3;
private Waypoint 4;
private Waypoint 5;
...
public Route(Waypoint 1, Waypoint 2, Waypoint 3, Waypoint 4, Waypoint 5) {
this.1 = 1;
this.1 = 2;
this.3 = 3;
this.4 = 4;
this.5 = 5;
}
}
无效 java 因为变量不能是数字。
我试过 使用 json schema 2 pojo and pojo sodhana library 之类的网站,但它们几乎可以完成我所做的事情。
我是 JSON 的新手,其他 API 很抱歉,如果显而易见的话。
而不是 Route
class 在根对象中使用 Map
:
private Map<String, Waypoint> route;
我正在尝试使用 Java
& GSON
反序列化来自 RouteXL 的响应,但是,路由作为单独的对象返回,而不是一个很痛苦的数组。有谁知道反序列化来自 RouteXL API1
的响应的简单方法?可悲的是 API2 也是如此。
Json 响应:
{
"id": "xJFPS2Z3",
"count": 4,
"feasible": true,
"route": {
"0": {
"name": "11 Main Street",
"arrival": 0,
"distance": 0
},
"1": {
"name": "19 Slate Road",
"arrival": 10,
"distance": 9.3
},
"2": {
"name": "234 Woodland Road",
"arrival": 18,
"distance": 14.5
},
"3": {
"name": "15 Great Eastern Road",
"arrival": 29,
"distance": 26.4
}
}
}
这几乎就像你需要创建一个像这样的 class 来保存所有回复:
public class Route {
private Waypoint 1;
private Waypoint 2;
private Waypoint 3;
private Waypoint 4;
private Waypoint 5;
...
public Route(Waypoint 1, Waypoint 2, Waypoint 3, Waypoint 4, Waypoint 5) {
this.1 = 1;
this.1 = 2;
this.3 = 3;
this.4 = 4;
this.5 = 5;
}
}
无效 java 因为变量不能是数字。
我试过 使用 json schema 2 pojo and pojo sodhana library 之类的网站,但它们几乎可以完成我所做的事情。
我是 JSON 的新手,其他 API 很抱歉,如果显而易见的话。
而不是 Route
class 在根对象中使用 Map
:
private Map<String, Waypoint> route;