![](/img/trans.png)
[英]RecyclerView not populating with Json data (Android) (Retrofit 2)
[英]JSON Array Retrofit and display it on a recyclerview Android Java
我正在尝试执行 @GET 请求,但收到 null 响应。 我熟悉使用以下内容实现响应主体
"billers": [
{
"name": "Biller full name",
"slug": "biller-short-name",
"fields": {
"FieldName": {
"type": "can be textfield, date, selectable or hidden",
"required": true,
"placeholder": "This is a field",
"defaultValue": "value1"
"regex": "only appears if the type is textfield e.g. ^[-a-zA-Z .]{1,100}$",
"dateFormat": "only appears if type is date e.g. yyyy-MM-dd",
"values": [
"value1": "only appears if type is selectable",
"value2": "value 2"
]
}
}
]
但这是我第一次实施这样的回应
[
{
"name": "Category full name",
"slug": "category-short-name",
"iconUrl": {
"android": {
"xhdpi": "xhdpi category icon url",
"mdpi": "mdpi category icon url",
"hdpi": "hdpi category icon url"
},
"ios": {
"3x": "3x biller icon url",
"retina": "retina biller icon url",
"nonRetina": "non-retina icon image url"
}
}
}
]
这是我的课程
这是我的错误,我得到一个 200 调用 api,但是当我尝试在 recyclerview 上显示它时,它说响应是 null
您没有显示如何将响应转换为 model。从第二个响应中您可以看到您的响应是PayBillsCategoryModel
列表
例如 Gson 你有这样的东西:
data class PayBillsCategoryModel(
@SerializedName("name ") val name: String? = null,
@SerializedName("name ") val slug: String? = null,
@SerializedName("name ") val iconUrl: IconUrl? = null
)
data class IconUrl(
@SerializedName("android") val android: Android? = null,
@SerializedName("ios") val ios: Ios? = null
)
data class Android(
@SerializedName("xhdpi") val xhdpi: String? = null,
@SerializedName("mdpi") val mdpi: String? = null,
@SerializedName("hdpi") val hdpi: String? = null,
)
data class Ios(
@SerializedName("3x") val x3: String? = null,
@SerializedName("retina") val retina: String? = null,
@SerializedName("nonRetina") val nonRetina: String? = null
)
所以在拨打 api 后,您的回复是
data class Response(val payBillsList: ArrayList<PayBillsCategoryModel>)
您需要将此列表传递给您的适配器
adapter.setData(payBillList)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.