2

我试图在这里解析一个json,但由于某种原因不断出现错误。我的代码是

    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);

错误是

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

我没有得到这个,因为 URL 是真实的并且得到了响应,我需要这方面的帮助

4

1 回答 1

1

您正在寻找的“预测”在响应中不存在。也许您正在寻找的是“hourly_forecast”。

NSArray* latestLoans = [res objectForKey:@"hourly_forecast"]; //2
NSArray *tmp = [latestLoans valueForKey:@"temp"];
于 2013-01-15T02:34:06.473 回答