You are currently viewing Referencing nameless objects in a nested JSON

Referencing nameless objects in a nested JSON

Hey guys.

I tried to look for an answer for this on google but I don’t know what the correct term for my problem is. Also, as you might have guessed I am new to Kotlin.

I am generating a nested JSON with gson with the root being this:
private data class MasterJson(val ships: MutableList<PlayerShipJson>)

That results in a JSON that is structured like this:
[

[

{

“playerShipJsonClassData”: {

“nation”: “usa”,

“shipIdNumber”: “4292753392”,

“shipTier”: 2,

“winRate”: “50.0”

},

“shipName”: “Sampson”

},

when I check the path for it there is an anonymous object that is represented in the path like this:
$.ships.[0]. I presume that anonymous object comes from the fact that I am passing a mutable list to the Array and it represents the index of that array.

I want to access the objects in this JSON but I do not know what syntax to use to access objects past that anonymous object.

jsonObject.getJSONObject([i]) for example does not work.

Suggestions on: A give that anonymous object a name on generation.

or B. how to access it would be greatly appreciated.

Thank you

submitted by /u/Luuk341
[link] [comments]