【发布时间】:2019-04-18 11:18:58
【问题描述】:
我正在传递这个 JSON http://www.mocky.io/v2/5cacde192f000078003a93bb
我试图只打印一个 category_name
当我像http://www.mocky.io/v2/5cb859344c0000092ed3d4df一样传递没有数据列表的对象时,我无法获取数据列表
private Category_name category_name;
public Category_name getCategoryName() {
return category_name;
}
}
public class Category_name {
@SerializedName("category_name")
public String name;
public String getName() {
return name;
}
}````
i can access that through the NewAdapter.java
with the following code
@Override
public void onBindViewHolder(NewsViewHolder holder, int position) {
Log.e("Its coming","NewAdapter");
ApiObject apiObject = apiObjectList.get(position);
holder.title.setText(apiObject.getCategoryName().getName());
}
with the same code I'm not able to get the data list
@SerializedName("data")
public List<Data> data;
public List<Data> getData() {
return data;
}
public class Data {
@SerializedName("details")
private Category_name category_name;
public Category_name getCategoryName() {
return category_name;
}
}
public class Category_name {
@SerializedName("category_name")
public String name;
public String getName() {
return name;
}
}
@Override
public void onBindViewHolder(NewsViewHolder holder, int position) {
Log.e("Its coming","NewAdapter");
ApiObject apiObject = apiObjectList.get(position);
holder.title.setText(apiObject.getData().getCategoryName().getName());
}
I'm not able to access the getCategoryName();
Please help thanks in advance
【问题讨论】:
-
对于你的新 json,它应该是 apiObject.getDetails().getCategoryName。另外你是如何解析你的 json 的?
-
在 Json Category_name 中是详细信息对象内的字符串变量。和您的模型类,您创建 Category_name 类。
-
根据您的 JSON 响应,您通过 POJO 解析的方式是错误的,或者您应该根据您的 POJO 更改您的 JSON 响应。
-
-@VivekMishra 我无法通过 apiobject 访问 getDetails
标签: java android json retrofit