G
G
goodTimes2017-09-15 08:58:03
iOS
goodTimes, 2017-09-15 08:58:03

How to get data from weather? icon and description with SwiftyJSON?

Here is JSON , you need to get the description and icon fields from weather, but it still doesn’t work.

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
       
       let checkString = searchBar.text!.replacingOccurrences(of: " ", with: "%20")
       let url = URL(string: "http://api.openweathermap.org/data/2.5/weather?q=\(checkString),&appid=b9be245f75c83dbb63d7700aa9e6f98e")!
       
        do {
            
            let jsonResult = try Data(contentsOf: url)
            let json =   JSON(jsonResult)
        
            let city = json["name"].stringValue
          //  let temp = json["main"]["temp"].intValue
            let weather = json["weather"][0]["description"].stringValue 
}

here in weather comes an empty value
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
goodTimes, 2017-09-15
@goodtimes922

response ["weather"][0]["description].stringValue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question