[英]Get weather for specific date using Openweather API - parsing JSON response
[英]how can i get json response for weather response
我正在使用天氣地圖api來獲取當前的天氣,我確實得到了溫度,但我有問題得到它的描述
class WeatherResponse {
@SerializedName("sys")
var sys: Sys? = null
@SerializedName("main")
var main: Main? = null
@SerializedName("weather")
var weather: Weather? = null
}
class Main {
@SerializedName("temp")
var temp: Float = 0.0f
@SerializedName("humidity")
var humidity: Float = 0.0f
@SerializedName("pressure")
var pressure: Float = 0.0f
@SerializedName("temp_min")
var temp_min: Float = 0.0f
@SerializedName("temp_max")
var temp_max: Float = 0.0f
}
class Sys {
@SerializedName("country")
var country: String? = null
}
這是網址的回復
{"coord":{"lon":139,"lat":35},
"sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
"weather":[{"id":804,"main":"clouds","description":"overcast
clouds","icon":"04n"}],
"main":
{"temp":289.5,"humidity":89,"pressure":1013,"temp_min"
:287.04,"temp_max" :292.04},
"wind":{"speed":7.31,"deg":187.002},
"rain":{"3h":0},
"clouds":{"all":92},
"dt":1369824698,
"id":1851632,
"name":"Shuzenji",
"cod":200}
編輯:對不起,這是一個python解決方案。
如果將json字符串轉換為字典,則可以嘗試以下操作:
weather_dict = json.loads(json_str)
print(weather_dict['weather'][0]['description'])
輸出:
overcast clouds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.