I am trying to make weather app for a project and I am using openweathermap for my api. I got it to output some information but I can't figure out how to get the rest of the information. This is what comes out when I put it into Postman. How can I grab the info that is in {}, like the temp and the min and max temp? I know I can loop through it if it was an array but it's not.
So far I have tried to loop through it like an array and that didn't work:
if let mainJson = jsonObject["main"] as? [[String:AnyObject]]
{
for eachtemp in mainJson
{
if let temp = eachtemp["temp"] as? String
{
print("the temp is: ", temp)
}
}
}
This is the response from the api:
{
"coord": {
"lon": -88.75,
"lat": 41.93
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 281.24,
"pressure": 1019,
"humidity": 52,
"temp_min": 279.26,
"temp_max": 283.15
},
"visibility": 16093,
"wind": {
"speed": 7.7,
"deg": 280,
"gust": 11.3
},
"clouds": {
"all": 1
},
"dt": 1555176309,
"sys": {
"type": 1,
"id": 5706,
"message": 0.0073,
"country": "US",
"sunrise": 1555154275,
"sunset": 1555201965
},
"id": 420012399,
"name": "Aurora",
"cod": 200
}