2

I am trying to parse a json here but keep on getting errors for some reason. my code is

    NSString *string = [NSString stringWithFormat:@"http://api.wunderground.com/api/3c158b3b3cd6ce90/hourly/q/11758.json"];//, query];
NSString *string2 = [string stringByReplacingOccurrencesOfString:@" " withString:@"_"];
NSData* data = [NSData dataWithContentsOfURL:
                [NSURL URLWithString:string]];
NSError* error;

NSDictionary *res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

NSArray* latestLoans = [res objectForKey:@"forecast"]; //2
NSArray *tmp = [latestLoans valueForKey:@"temp"];
NSLog(@"temp: %@", tmp);

and the error is

temp: (null)
Entity: line 2: parser error : Start tag expected, '<' not found
{
^

I don't get this because the URL is real and gets a response, and I need help with this

6
  • What is the point of string2? It looks like it isn't used. Commented Jan 15, 2013 at 2:22
  • it was but for right now i'm just not using it Commented Jan 15, 2013 at 2:23
  • 1
    I don't see a key "forecast" in the response but there is "hourly_forecast". That said, I don't see any reason that would cause the error you are getting - is that coming from later code? Commented Jan 15, 2013 at 2:27
  • yea that was the problem i did that because in the xml version there was a forecast key. thanks Commented Jan 15, 2013 at 2:30
  • Looks like some xml parsing error. Are you parsing some xml using xml parsers? Commented Jan 15, 2013 at 2:32

1 Answer 1

1

What you are looking for, "forecast", does not exist in the response. Perhaps what you are looking for is "hourly_forecast".

NSArray* latestLoans = [res objectForKey:@"hourly_forecast"]; //2
NSArray *tmp = [latestLoans valueForKey:@"temp"];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.