The response is not a simple NSDictionary object. It is a dictionary of arrays and dictionaries that may contain other arrays and dictionaries etc.
You have to know what is the structure of your response (for example by NSLogging it).
Try: NSLog(@"%@", weatherReturn);
{...}
means a NSDictionary
object.
(...)
means a NSArray
object
I changed your code to prove that the params you're looking for are not nil
.
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlNSString = [NSString stringWithFormat:@"http://api.wunderground.com/api/%@/forecast/q/Chicago.json",kWeatherAPIKey];
NSURL *url = [NSURL URLWithString:urlNSString];
NSData *weatherCall = [NSData dataWithContentsOfURL:url];
NSError *error;
id weatherReturn = [NSJSONSerialization JSONObjectWithData:weatherCall options:0 error:&error];
NSLog(@"%@", weatherReturn);
id forecast = [weatherReturn valueForKey:@"forecast"];
id simpleforecast = [forecast valueForKey:@"simpleforecast"];
id forecastday = [simpleforecast valueForKey:@"forecastday"];
id firstPartOfDailyForecast = [forecastday firstObject];
id avehumidity = [firstPartOfDailyForecast valueForKey:@"avehumidity"];
id date = [firstPartOfDailyForecast valueForKey:@"date"];
id pretty = [date valueForKey:@"pretty"];
id ampm = [date valueForKey:@"ampm"];
NSLog(@"Ave:%@\nPretty:%@\nAM/PM:%@", avehumidity, pretty, ampm);
}
IMPORTANT
I'm not calling valueForKey:
method on weatherReturn all the time, but i'm getting deeper and deeper inside the response structure.
This is how the structure looks like for param with key "ampm"
--NSDictionary (response)
----NSDictionary for key forecast
-------NSDictionary for key simpleforecast
---------NSArray for key forecastday
-----------NSDictionary as first array object
-------------NSDictionary for key date
---------------NSString for key ampm
EDIT:
I just found this tool, you might find it helpful :)
How to use it:
- Place your request (but change API KEY :)) request into a browser
http://api.wunderground.com/api/YOUR_API_KEY/forecast/q/Chicago.json
- Copy the API response to the tool's 'Text' page.
- Go to 'Viewer' page and analize the response.