Home > Blockchain >  KOTLIN SerializedName Json Descend to the lower value
KOTLIN SerializedName Json Descend to the lower value

Time:10-22

JSON CODE :
"title": {
"rendered": "TITLE"
},
"content": {
"rendered": "CONTENT",
"protected": false
},

My Class :

data class Icerik(
    @SerializedName("title")
    val baslik:String?,
    @SerializedName("content")
    val icerik:String?,
    @SerializedName("date")
    val tarih:String?,
    @SerializedName("jetpack_featured_media_url")
    val gorsel:String?,) {
}

My content is in content -> rendered in . How to i can reach my content ? How can I get to the bottom ?

CodePudding user response:

You need to create a data class to get the content of the json object. Like:

data class Icerik(
    @SerializedName("title")
    val baslik: String?,
    @SerializedName("content")
    val icerik: Content?,
    @SerializedName("date")
    val tarih: String?,
    @SerializedName("jetpack_featured_media_url")
    val gorsel: String?,
) {
    data class Content(
        @SerializedName("rendered")
        val content: String?,
        @SerializedName("protected")
        val bool: Boolean?,
    )
}
  • Related