【发布时间】:2021-12-29 05:37:24
【问题描述】:
我正在接收我想要解析的 JSON:
[
{
"id": "f9952c24-1b44-4379-9aef-b10075e93562",
"sections": [
{
"id": "7fe9f47e-9cfe-46c7-9c77-f729b9fb98a4",
"type": "vehicle",
"summary": {
"duration": 23377,
"length": 480501,
"baseDuration": 22140
}
}
]
}
]
我的 Java 模型类(由 json2pojo 生成):
public class HereRoute {
@SerializedName("routes")
@Expose
private List<Route> routes = null;
}
public class Route {
@SerializedName("id")
@Expose
private String id;
@SerializedName("sections")
@Expose
private List<Section> sections = null;
}
public class Section {
@SerializedName("id")
@Expose
private String id;
@SerializedName("type")
@Expose
private String type;
@SerializedName("summary")
@Expose
private Summary summary;
}
public class Summary {
@SerializedName("duration")
@Expose
private Integer duration;
@SerializedName("length")
@Expose
private Integer length;
@SerializedName("baseDuration")
@Expose
private Integer baseDuration;
}
我只对要保存在数据库中的摘要长度感兴趣。 如何解析它以仅从 json 中获取每个对象的摘要长度? 我需要像 Gson 这样的东西吗?
【问题讨论】:
-
这能回答你的问题吗? How to parse JSON in Java