[英]Http request: How can I get a value inside curly braces
I try to make a Weather App.我尝试制作一个天气应用程序。 And when I try to for example: Get timezone(which is outside the curly braces) it works, but when I try to get the temperature it doesn't.
例如,当我尝试获取时区(在花括号之外)时,它可以工作,但是当我尝试获取温度时却没有。 Here is where I want it from
这是我想要的地方
And this is my Class
这是我的 Class
data class WeatherClass (
//here I don't know how to get the temp
@field:Json(name = "main")
val temp: Double,
val timezone: Int,
val id: Int
)
It is a nested Json
, you cannot directly access temp
using main
, create a Main
class and add temp
inside it它是一个嵌套的
Json
,您不能使用main
直接访问temp
,创建一个Main
class 并在其中添加temp
data class Main(val temp: Double)
Then add Main
inside WeatherClass
然后在
WeatherClass
添加Main
data class WeatherClass (
val main: Main,
val timezone: Int,
val id: Int){
val temp:Double
get() = main.temp
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.