java - 在 Android 上使用 Retrofit 解析嵌套的 json
问题描述
我retrofit
在我的android应用程序中使用。在我的 webapi 中,有一个我需要解析的嵌套 json 结果。不是嵌套的很好,但是当我遇到嵌套的时候,我似乎无法解析它们。
这是我的 json 示例。我把它缩短了一点,但都一样。当我执行调用方法时,它只是绕过了 onResponse 或 onFailure。我在想我在我的类文件中犯了一个错误,但我不知道是什么或如何。
JSON:
[
{
"name": "All joined for mobile",
"selectedOnes": [
"1",
"2"
],
"lines": [
{
"details": "",
"cancelDetails": null,
"isCancel": null,
"hours": [
{
"arrivalTime": "",
"departTime": "07:15:00"
},
{
"arrivalTime": "07:30:00",
"departTime": ""
}
]
},
{
"details": "",
"cancelDetails": null,
"isCancel": null,
"hours": [
{
"arrivalTime": "",
"departTime": "07:30:00"
},
{
"arrivalTime": "07:45:00",
"departTime": ""
}
]
}
]
}
]
ParsedJsonClass.java:
public class ParsedJsonClass {
@SerializedName("name")
@Expose
private String name;
@SerializedName("selectedOnes")
@Expose
private List<String> selectedOnes = null;
@SerializedName("lines")
@Expose
private List<lines> lines = null;
public class lines {
@SerializedName("details")
@Expose
private String details;
@SerializedName("cancelDetails")
@Expose
private Object cancelDetails;
@SerializedName("isCancel")
@Expose
private Object isCancel;
@SerializedName("hours")
@Expose
private List<hours> hours = null;
public class hours {
@SerializedName("arrivalTime")
@Expose
private String arrivalTime;
@SerializedName("departTime")
@Expose
private String departTime;
}
}
}
解决方案
推荐阅读
- python - Python Pandas 查找另一个数据框返回多个匹配项
- java - Java String.getBytes(charset) 和 new String(bytes, charset) 有两个不同的字符集
- c# - 在xaml上将负值显示为正
- apache-nifi - Apache NiFi 和 StreamSet
- ruby - 迁移以创建已存在于数据库中的表
- mobile - 在 Safari 中“显示桌面站点”失败
- html - 我应该在不使用 ng new myapp 命令的情况下创建一页 angular 6 应用程序吗?
- python - 如何将用户名转换为不和谐的 ID?
- sql - 如何从另一个表设置 ID 值
- django - 如何使用特定存储桶创建 django 自定义文件字段以上传到 amazon s3