我是 Moshi 的新手,我正在尝试使用 Retrofit 从一个扩展项目数组列表的类中解析数据,但出现此错误:
com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $
班级:
class CarSelection: ArrayList<CarItem>()
data class CarItem(
@field:Json(name = "type") val type: String,
@field:Json(name = "name") val name: String,
@field:Json(name = "color") val color: String,
@field:Json(name = "image") val image: String
)
改造服务:
fun getRemoteService(baseUrl :String, client : OkHttpClient): MyRemoteService {
return Retrofit.Builder()
.baseUrl(baseUrl)
.client(client)
.addConverterFactory(MoshiConverterFactory.create())
.build()
.create(MyRemoteService::class.java)
}
提前致谢