[英]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和pojo sodhana 库之类的站点,但它们几乎可以完成我所做的事情。
我对 JSON 和 Rest API 很抱歉,如果很明显的话。
而是在根 object 中使用Map
Route
class :
private Map<String, Waypoint> route;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.