4thSpace 4thSpace - 10 months ago 47
Swift Question

How to parse this with SwiftyJSON?

I'm using SwiftyJSON with NSURLSession.sharedSession().dataTaskWithURL and openweathermap.org. I'm getting back data and can pull out values. But I'm not having any luck trying to get "main" in the sample below.

Here's the first part of the JSON that comes back:

"cod" : 200,
"weather" : [
"id" : 800,
"description" : "clear sky",
"main" : "Clear",
"icon" : "01d"

if let data = data {
let json = JSON(data: data)
main = json["weather"]["main"].stringValue

doesn't contain anything.
also doesn't contain anything. Any ideas what I'm doing wrong?


Try doing this to get the first item in the array:


According to this line in SwiftyJSON documentation example:


Is the way to get items in a JSON array