【发布时间】:2019-10-31 07:48:04
【问题描述】:
我已经搜索了其他相关问题,但找不到我的答案。
这是我的 JSON:命名为 appointments.json
[
{
"title": "Primary Care",
"text": "Schedule a Primary Care appointment online.",
"image": "http://i.imgur.com/DvpvklR.png"
},
{
"title": "Primary Care",
"text": "Schedule a Primary Care appointment online.",
"image": "http://i.imgur.com/DvpvklR.png"
},
{
"title": "Primary Care",
"text": "Schedule a Primary Care appointment online.",
"image": "http://i.imgur.com/DvpvklR.png"
},
{
"title": "Primary Care",
"text": "Schedule a Primary Care appointment online.",
"image": "http://i.imgur.com/DvpvklR.png"
}
]
这里是列表对象类:
@Parcelize
data class AppointmentsListItem(
@Expose
@SerializedName("title")
val title: String = "",
@Expose
@SerializedName("text")
val text: String = "",
@Expose
@SerializedName("image")
val image: String = "") : IAppointmentsListItem
这是我的错误发生的地方:
val gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation()
.create()
private val listType = object : TypeToken<List<AppointmentsListItem>>() {}.type
val apiList: List<AppointmentsListItem> = gson.fromJson("appointments.json", listType)
STRING 到底是从哪里来的??我的 Json 响应是这些 ListItems 的数组,我以 [] 开始响应,为什么它读取字符串?
【问题讨论】:
标签: android arrays json kotlin gson