我正在尝试解析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
{
^
我没有得到这个,因为网址是真实的并得到回复,我需要帮助
答案 0 :(得分:1)
您要查找的内容,“预测”,在回复中不存在。也许你正在寻找的是“hourly_forecast”。
NSArray* latestLoans = [res objectForKey:@"hourly_forecast"]; //2
NSArray *tmp = [latestLoans valueForKey:@"temp"];