Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 改装包含由数组表示的另一个对象的对象调用_Java_Json_Object_Retrofit - Fatal编程技术网

Java 改装包含由数组表示的另一个对象的对象调用

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",

我有json数据:

[
  {
    "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
实体的
列表。您只需创建一个具有正确属性的
计划
类,并将
私有列表计划
添加到
路由
对象中