首页 > 解决方案 > 从 Kotlin 和 okhttp 中的函数检索变量结果

问题描述

我是 Kotlin 的新手,非常感谢您的帮助。我能够在 getVariable() 函数中获取 jsonStringArray 变量的值,但我不确定如何在 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) {
    }
}
)
}

标签: androidkotlinretrofitokhttpokhttp3

解决方案


推荐阅读