android - 从 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) {
}
}
)
}
解决方案
推荐阅读
- c - 原因:#1546-D:(ULP 15.1)检测到连续位域分配。建议改用位掩码
- apache - 如何使用 RewriteRule 和 ProxyPass 获得条件代理?
- c# - 如何正确单元测试异步套接字连接操作并避免 Thread.Sleep?
- gremlin - 如何将计数结果添加到 valuemap?
- javascript - 如何解决 IE 中的此错误?SCRIPT1003:预期为“:”
- ios - 在iOS中被拒绝后有什么方法可以请求许可
- angular6 - Angular 6(模糊)功能
- javascript - 为什么 TypeScript 假定解构数组的所有元素都与源数组的项类型匹配?
- mysql - 为什么我不能得到查询的结果
- twilio - 如何对传入的 SMS 进行“双重 webhook”?