【问题标题】:how to parse custom json array list in kotlin using GSON如何使用 GSON 解析 kotlin 中的自定义 json 数组列表
【发布时间】:2019-01-02 14:06:13
【问题描述】:

这是我的数据类,需要解析link类型的arraylist

class DetailResponse {
    data class BasicInfo (
        @SerializedName("favorite") val isFavorite: Boolean,
        @SerializedName("screenshots") val screenshots: ArrayList<Link>
    )

    data class Link (
        @SerializedName("href") val href: String
    )
}

【问题讨论】:

  • 您的问题没有描述您的问题陈述,您能否尝试更详细地说明您想要什么
  • 我的 json 树嵌套如上所述,我想要截图的数组列表
  • 你的 json 在哪里?
  • 请分享您的 json。

标签: android serialization kotlin gson


【解决方案1】:

你所做的是正确的。现在你只需要使用 Gson 将这个 JSON 转换为对象

val gson = Gson()
val detailResponse = gson.fromJson(resp,DetailedResponse::class.java)

“resp”是你的 json 字符串。

【讨论】:

    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2021-09-30
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多