以JSON数组
问题描述:
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
}
}
- “类天气” 存储值
答
尝试像下面这样。
var descriptionString = jsonObj["weather"]![0]["description"]