我需要从 Sandwich 类中获取 breadType 属性。我有两个可序列化的类:
@Serializable
class MyFood {
var name: String? = null
var price: Int? = null
var sand: Sandwich? = null
}
@Serializable
class Sandwich{
var breadType: String? = null
}
而这个 JSON:
"MyFood": {
"name": "Sandwich double",
"price": 100.00,
"breadType": 100.00
}
我得到 JsonUnknownKeyException 异常:
"Strict JSON encountered unknown key: breadType\nYou can disable strict mode to skip unknown keys"
请问我做错了什么!?