【发布时间】:2018-08-01 03:41:08
【问题描述】:
我有 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 对象插入到 Route 模型中?我对(据我了解)它是一个包含数组的对象感到困惑,我不确定在这种情况下如何表示它。以及如何在改造电话中实际从中获取数据?我需要为每条路线获取每个目的地。
【问题讨论】:
-
这是
List的Schedule实体。您只需要创建一个具有正确属性的Schedule类并将private List<Schedule> schedules'添加到您的Route对象