-2

I have this data from JSON from OpenWeatherMap API

"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],

I have not idea how to access property "description"... I am using Alamofire and SwiftyJSON.

I have no problem get value from

"sys":{"type":1,"id":5091,"message":0.0237,"country":"GB","sunrise":1436673470,"sunset":1436732035}

using this piece of code:

var weatherJson = JSON(json!)
var temperature = weatherJson["main", "temp"].double
.
.
.
func setLabels() {

    if let temp = self.weather?.temp{
     //code
    }
}

but that don't work with extra brackets []...

EDIT: 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
  }
}
  • "class weather" for stored values
John Slegers
  • 45,213
  • 22
  • 199
  • 169
Pan Mluvčí
  • 1,242
  • 2
  • 21
  • 42

1 Answers1

2

Try something like the following.

var descriptionString = jsonObj["weather"]![0]["description"]
Shamas S
  • 7,507
  • 10
  • 46
  • 58