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
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
data class Main(val temp: Double)
Then add Main
inside WeatherClass
data class WeatherClass (
val main: Main,
val timezone: Int,
val id: Int){
val temp:Double
get() = main.temp
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.