【发布时间】:2015-12-07 21:11:36
【问题描述】:
我正在使用与 GitHub API 配合使用的 Retrofit 2.0。
所以我有兴趣获得
parent" - > "full_name"
但是当我尝试运行我的代码时,这个值等于null。
我尝试了很多方法,但没有任何积极的结果。所以我被这个问题困住了。
下面是我要解析的 JSON 响应:
{
"id": 45136403,
"name": "android_guides",
"full_name": "BohdanSamusko/android_guides",
"owner": {
"login": "BohdanSamusko",
},
"parent": {
"name": "android_guides",
"full_name": "codepath/android_guides",
"owner": {
"login": "codepath",
"id": 3710273,
},
},
}
POJO 类:
public class Repo {
@SerializedName("name") // name of repository
private String name = "";
@SerializedName("full_name") // full name of repository
private String name = "";
@SerializedName("parent") // this is the nested object which I want to parse
private Parent parent = "";
}
class Parent{
@SerializedName("full_name")
private String full_name = ""; // full name of repository parent. This value I want to parse.
}
我的 POJO 类是否正确?为什么我不能得到
parent" ->"full_name"
【问题讨论】:
-
如果你尝试访问其他属性是
null吗?您可以显示您进行远程访问的代码部分吗?你确定回复不是null吗?
标签: java android json gson retrofit