简体   繁体   中英

iOS JSON Parsing error

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

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"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM