使用Reform在recyclerview适配器中Acess嵌套JSON数据



我使用改装2.4.0从使用PHP作为Web服务的mysql数据库中获取数据。我以以下格式返回JSON数据:-

{
"result": [
{
"category_Id": 1,
"category_Name": "Jyotirling",
"category_Image": "jyotirling.jpg",
"total_Mandir": 12
},
{
"category_Id": 2,
"category_Name": "Akshardham",
"category_Image": "akshardham.jpg",
"total_Mandir": 2
},
{
"category_Id": 3,
"category_Name": "AshtaVinayak",
"category_Image": "ashtavinayak.jpg",
"total_Mandir": 8
}
],
"message": "Data found",
"status": "200"
}

我的Pojo课程是

1(

public class MandirCategory {
@SerializedName("result")
@Expose
private List<MandirCategoryResults> result = null;
@SerializedName("message")
@Expose
private String message;
@SerializedName("status")
@Expose
private String status;
public List<MandirCategoryResults> getResult() {
return result;
}
public void setResult(List<MandirCategoryResults> result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

2( 嵌套数据的结果类

public class MandirCategoryResults {
@SerializedName("category_Id")
@Expose
private Integer categoryId;
@SerializedName("category_Name")
@Expose
private String categoryName;
@SerializedName("category_Image")
@Expose
private String categoryImage;
@SerializedName("total_Mandir")
@Expose
private Integer totalMandir;
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public String getCategoryImage() {
return categoryImage;
}
public void setCategoryImage(String categoryImage) {
this.categoryImage = categoryImage;
}
public Integer getTotalMandir() {
return totalMandir;
}
public void setTotalMandir(Integer totalMandir) {
this.totalMandir = totalMandir;
}
}

但现在我不知道如何访问回收视图中嵌套类的数据。

我可以访问回收视图中的消息属性,如下所示:

String msg = listData.get(i).getMessage();

但是如何得到categoryName的值呢?

编辑:用于获取JSON数据的代码

@GET("getMandirCategories.php")
Call<List<MandirCategory>> getMandirCategoriesREST();

您是否试图用RecyclerView显示列表?如果不是,假设解析是正确的,这应该有效(indexMandirCategory表示List中的索引(:

String category = listData.get(i).getResult().get(indexMandirCategory).getCategoryName();

最新更新