JSON Returns Missing Quotes In Objective C

  • 1
  • Problem
  • Updated 5 years ago
I'm pulling the weather feed into an iPhone app I'm building and for some reason, the JSON returned has certain objects not surrounded in quotes. This makes it not possible to get the data since I can't access that particular key then. The part that's strange is if you take the same call and put it in a browser, it works just fine. Is there some sort of known bug with pulling these feeds as JSON into Objective C?

Sample Code:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.wunderground.com/api/25d9e...", latitude, longitude]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonError = nil;
NSDictionary *weather = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonError];

Sample Return:

"temperature_string" = "75.5 F (24.2 C)";
"visibility_km" = "16.1";
"visibility_mi" = "10.0";
weather = Clear;
"wind_degrees" = 274;
"wind_dir" = West;

Notice how "weather" doesn't have quotes? This is the issue and it persists randomly through the returned JSON.

Thanks in advance for your help!
Photo of brustj

brustj

  • 1 Post
  • 0 Reply Likes

Posted 5 years ago

  • 1

Be the first to post a reply!