I’m sending API Call and getting response like that
{ "12312412312124123124": { "id": "12312412312124123124", "content": [ { "id": 41419969} ] },
"141412312412312521": { "id": 141412312412312521", "content": [ { "id": 41419969} ] }}
how can I handle to parse this json object or create data class for it , I’ve searched for custom deserialization but can’t find answer…
This is my call execution code
builder.build().newCall(request).execute().use { response ->
if (response.isSuccessful) {
val responseBody = response.body?.string()
if (!responseBody.isNullOrBlank()) {
val readings = gson.fromJson(responseBody, MyClassForParsing::class.java)
} else {
println("Response body is empty.")
}
} else {
println("Request failed with code: ${response.code}")
}
}
2
Answers
i am using retrofit to do networking. u can processing json to variabel too
u can read it here: https://betterprogramming.pub/how-to-use-retrofit-for-networking-in-android-for-beginners-ef6bae5ef113
Response Data Class (Don’t forget to add
@SerializedName
)Variable key values are available in the relevant json data
Last Step call enqueue