How Can Correctly Parse Nested Json Object Using Retrofit 2.0 (kotlin)?
The following JSON object is what I'm receiving from server (get request). I need to get the coordinate values (lat, long) { 'loc': { 'type': 'Point', 'coordina
Solution 1:
Add one more class Location which represents the tested object type.
packagecom.zowye.API.Modelsimportcom.google.gson.annotations.SerializedNameclassLocation (
var type: String?,
var coordinates: Float[]?
)
classSalao
(
@SerializedName("loc") var coordinate: Location,
var city: String?,
var name: String?
)
Solution 2:
You should create a data class for "loc"
dataclassSalao(
@SerializedName("loc")
val location : Location,
val city : String,
val name : String,
@SerializedName("_id")
val id : String
)
dataclassLocation (
val type : String,
val coordinates : Array<Float>
)
Post a Comment for "How Can Correctly Parse Nested Json Object Using Retrofit 2.0 (kotlin)?"