我正在尝试通过一个简单的适配器示例来解析一些json
// sample json i'm trying to parse
val response = "{ kind : 'listing', data : { children : [{ data : {}}, { data : {}}, { data : {}}] } }"
val moshi = Moshi.Builder()
.add(ListingAdapter())
.build()
val adapter = moshi.adapter(Listing::class.java)
val listing = adapter.fromJson(response)
class ListingAdapter {
@FromJson
fun fromJson(response : String) : Listing {
return Listing()
}
@ToJson
fun toJson(listing : Listing) : String {
return ""
}
}
class Listing {
var kind : String? = null
}
运行此命令时,出现此异常
Exception in thread "main" com.squareup.moshi.JsonDataException: Expected a string but was BEGIN_OBJECT at path $
。
我尝试查看其他问题,但没有找到与我的情况相符的内容。