0

So i have this problem where im asking for an array but im getting an object.

im getting some objects like this :

{
    "2324": {
        "Install_Date": "2013-11-28",
        "LATITUDE": 0.51664504,
        "LONGITUDE": 0.30964532,
        "Module_Count": 14,
    },
... and some more objects ...
}

Where the 2324 is dynamic, so it can change.

How can i get this data from retrofit ?

im using serialized and asking for a list of my Object that i created.

My custom object:

data class Asset(
    @SerializedName("Install_Date")
    val assetInstallDate: String,

    @SerializedName("LATITUDE")
    val LATITUDE: Double,

    @SerializedName("LONGITUDE")
    val LONGITUDE: Double,

    @SerializedName("Module_Count")
    val assetModuleCount: Int,
)

and my call is:

call.enqueue(object : Callback<List<Asset>>{
....
}
  • You can look at the object and use `object.keys()` to get all the keys. https://stackoverflow.com/questions/13573913/android-jsonobject-how-can-i-loop-through-a-flat-json-object-to-get-each-key-a – BlackHatSamurai Mar 01 '23 at 18:59
  • Does this answer your question? [Android JSONObject - How can I loop through a flat JSON object to get each key and value](https://stackoverflow.com/questions/13573913/android-jsonobject-how-can-i-loop-through-a-flat-json-object-to-get-each-key-a) – BlackHatSamurai Mar 01 '23 at 18:59
  • @BlackHatSamurai i know how to do that way, but with retrofit, how can i do that ? – Francisco Torres Mar 01 '23 at 19:04
  • Change your callback signature to `Callback` – BlackHatSamurai Mar 01 '23 at 19:08
  • 1
    Does this answer your question? [kotlin retrofit expected begin\_array but was begin\_object at line 1](https://stackoverflow.com/questions/64326723/kotlin-retrofit-expected-begin-array-but-was-begin-object-at-line-1) – JustSightseeing Mar 01 '23 at 19:09
  • @JustSightseeing yes, thanks.. Well at least i think it does. Just a curiosity, what does expose means in retrofit? – Francisco Torres Mar 01 '23 at 19:12
  • https://www.javadoc.io/doc/com.google.code.gson/gson/2.6.2/com/google/gson/annotations/Expose.html – JustSightseeing Mar 01 '23 at 19:17

0 Answers0