我使用这个类来存储数据
public class Item(var name:String,
var description:String?=null){
}
并在ArrayList中使用它
public var itemList = ArrayList<Item>()
Use this code to serialize the object
val gs=Gson()
val itemListJsonString = gs.toJson(itemList)
反序列化
itemList = gs.fromJson<ArrayList<Item>>(itemListJsonString, ArrayList::class.java)
But this method will give me LinkedTreeMap
, not Item
, I cannot cast LinkedTreeMap to Item
在Kotlin中反序列化为json的正确方法是什么?