Java 改装包含由数组表示的另一个对象的对象调用
我有json数据:Java 改装包含由数组表示的另一个对象的对象调用,java,json,object,retrofit,Java,Json,Object,Retrofit,我有json数据: [ { "RouteNo": "004", "RouteName": "POWELL/DOWNTOWN/UBC", "Direction": "WEST", "Schedules": [ { "Destination": "UBC", "ExpectedCountdown": -4, }, { "Destination": "Downtown",
[
{
"RouteNo": "004",
"RouteName": "POWELL/DOWNTOWN/UBC",
"Direction": "WEST",
"Schedules": [
{
"Destination": "UBC",
"ExpectedCountdown": -4,
},
{
"Destination": "Downtown",
"ExpectedCountdown": -6,
}
]
},
{
"RouteNo": "006",
"RouteName": "Grange str",
"Direction": "South",
"Schedules": [
{
"Destination": "Victoria",
"ExpectedCountdown": -9,
},
{
"Destination": "College station",
"ExpectedCountdown": -15,
}
]
}
]
我有我的模型Route.java:
public class Route {
public String getRouteNo() {
return RouteNo;
}
public void setRouteNo(String routeNo) {
RouteNo = routeNo;
}
public String getRouteName() {
return RouteName;
}
public void setRouteName(String routeName) {
RouteName = routeName;
}
public Route(String routeNo, String routeName) {
RouteNo = routeNo;
RouteName = routeName;
}
private String RouteNo;
private String RouteName;
}
我的问题是如何将json数据中的Schedules对象插入到路由模型中?我很困惑(据我所知)它是一个包含数组的对象,我不知道在这种情况下如何表示它。在改装电话中如何从中获取数据?我需要知道每条路线的每个目的地 更新
路线
为:
public class Route {
public String getRouteNo() {
return RouteNo;
}
public void setRouteNo(String routeNo) {
RouteNo = routeNo;
}
public String getRouteName() {
return RouteName;
}
public void setRouteName(String routeName) {
RouteName = routeName;
}
public Route(String routeNo, String routeName) {
RouteNo = routeNo;
RouteName = routeName;
}
private String RouteNo;
private String RouteName;
private List<Schedule> schedules; // add mutators with @JsonProperty annotation
}
公共类路由{
公共字符串getRouteNo(){
返回RouteNo;
}
公共void setRouteNo(字符串routeNo){
RouteNo=RouteNo;
}
公共字符串getRouteName(){
返回路由名称;
}
公共无效setRouteName(字符串routeName){
路由名称=路由名称;
}
公共路由(字符串routeNo、字符串routeName){
RouteNo=RouteNo;
路由名称=路由名称;
}
私有字符串路由;
私有字符串路由名称;
私有列表计划;//添加带有@JsonProperty注释的变量
}
然后按照上述JSON所述创建
Schedule
类,该类可能重复,它是Schedule
实体的列表。您只需创建一个具有正确属性的计划
类,并将私有列表计划
添加到路由
对象中