My JSON
[
"first_flight": "2010-12-08",
"flickr_images": [
"https://i.imgur.com/9fWdwNv.jpg",
"https://live.staticflickr.com/8578/16655995541_7817565ea9_k.jpg",
"https://farm3.staticflickr.com/2815/32761844973_4b55b27d3c_b.jpg",
"https://farm9.staticflickr.com/8618/16649075267_d18cbb4342_b.jpg"
],
"flickr_images": [
"https://farm8.staticflickr.com/7647/16581815487_6d56cb32e1_b.jpg",
"https://farm1.staticflickr.com/780/21119686299_c88f63e350_b.jpg",
"https://farm9.staticflickr.com/8588/16661791299_a236e2f5dc_b.jpg"
],
]
My code
val result = URL("https://api.spacexdata.com/v4/dragons").readText()
val parser: Parser = Parser()
val stringBuilder: StringBuilder = StringBuilder(result)
jsonArray = parser.parse(stringBuilder) as JsonArray<JsonObject>
....
**rocket.image = jsonArray.string("flickr_images")[i]?.get(0).toString() - doesnt work**
Have java.lang.ClassCastException: com.beust.klaxon.JsonArray cannot be cast to java.lang.String
first point is JsonObject is key-value pair .JsonArray is Collection of JsonObject . so flickrimages is not a proper jsonArray Format.flickrimages is a List of String.so error comes.
and as per your Question you cannot get values from both flickrimages since this json has two keys with same name "flickrimages".so if you get value with key "flickrimages" by default only last added one value comes.
so its better to change the formatofjson that comes from url