[英]How to display table from the database using json response in Android? (I'm getting JsonArray Fail error in this code)
[英]I'm passing a list of JSON file is not getting display in the Android application
我正在传递这个 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 2 pojo 转换来创建适当的 json 数据模型类http://www.jsonschema2pojo.org/
将整个示例对象传递给适配器构造函数。
我认为您需要根据您的 JSON 响应遵循这些 POJO 解析方式。
public class Data{
@Serialization("status")
@Expose
private String status;
@Serialization("data")
@Expose
private List<MyData> data;
然后
public class MyData{
@Serialization("details")
@Expose
private List<Details> getDetails();
@Serialization("product_count")
@Expose
private String Product_count;
@Serialization("products")
@Expose
private List<Products> getProducts();
//setter and getters
}
详细信息
Public class Details{
@Serialization("category_id")
@Expose
private String category_id;
@Serialization("category_name")
@Expose
private String category_name;
@Serialization("category_icon")
@Expose
private String category_icon;
//setter and getters
}
产品中心
Public class Products{
@Serialization("product_id")
@Expose
private String product_id;
@Serialization("product_name")
@Expose
private String product_name;
@Serialization("product_image")
@Expose
private String product_icon;
etc
//setter and getters
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.