0
Gson類可以包含JSONObject類型的字段嗎? 這裏是我GSON類GSON類中的JSONObject字段 - 仍爲空
class Item {
@Expose
var name: String? = ""
@Expose
var type: String? = ""
@Expose
@SerializedName("agr")
var aggregate: JSONObject? = null
@Expose
@SerializedName("seg")
var segments: JSONObject? = null
@Expose
@SerializedName("ts")
var timestamp: String? = ""
}
的JSONObject的領域段和總仍然連載時(使用默認改造GsonConverterFactory)一個空的JSONObject。這是我得到的。任何建議讓它寫?
{"items":[{"agr":{},"name":"Logged In","seg":{},"ts":"2017-10-17T12:20:32Z","type":"event"}]}
你需要一個自定義的反序列化器,你可以在這裏找到更多的信息:https://stackoverflow.com/questions/16590377/custom-json-deserializer-using-gson – Jibbo