Casting JSONArray to Iterable<JSONObject> - Kotlin

Viewed 4997

I am using Json-Simple in Kotlin.

In what situations could this cast:

val jsonObjectIterable = jsonArray as Iterable<JSONObject>

Become dangerous? jsonArray is a JSONArray object.

2 Answers

Following is rather a simple implementation.

Suppose Your Object is Person

data class Person( val ID: Int, val name: String): Serializable
val gson = Gson()
val persons: Array<Person> = gson.fromJson(responseSTRING, Array<Person>::class.java)

Now persons is an Array of Person

Related