Retrieving a Variable result from a function in Kotlin and okhttp


#1

I am new to Kotlin and Your help is highly appreciated. I am able to get the value of jsonStringArray variable within getVariable() function but I am not sure how to retrieve the value outside the function in kotlin.

//Need help on the below variable outside getVariable function
val output=jsonStringArray.getVariable()???
//Working Code
private fun getVariable() {
val itemDetailURL=“https://www.google.com
val client= OkHttpClient()
val request= Request.Builder().url(itemDetailURL).build()
client.newCall(request).enqueue(object: Callback
{
override fun onResponse(call: Call?, response: Response?) {
val jsonStringArray=response?.body()?.string()
println(“JSON Output: $jsonStringArray”)

}
override fun onFailure(call: Call, e: IOException) {
}

}
)
}