-2
SWIFT訪問我從JSON這個數據從OpenWeatherMap API以JSON數組
"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],
我不知道如何訪問屬性「說明」 ...... 我使用Alamofire和SwiftyJSON。
我從
"sys":{"type":1,"id":5091,"message":0.0237,"country":"GB","sunrise":1436673470,"sunset":1436732035}
使用這段代碼沒有問題GET值:
var weatherJson = JSON(json!)
var temperature = weatherJson["main", "temp"].double
.
.
.
func setLabels() {
if let temp = self.weather?.temp{
//code
}
}
但不額外括號[]
工作...
編輯: SOLUTION - >
func getWeatherData(urlString: String) {
var weatherJson = JSON(json!)
var description = weatherJson["weather"][0]["description"].stringValue
}
func setLabels() {
if let description = self.weather?.desc{
self.descriptionLabel.text = description
}
}
- 「類天氣」 存儲值