我试图在这里解析一个 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 是真实的并且得到了响应,我需要这方面的帮助
最佳答案
您要查找的“预测”在响应中不存在。也许您正在寻找的是“hourly_forecast”。
NSArray* latestLoans = [res objectForKey:@"hourly_forecast"]; //2
NSArray *tmp = [latestLoans valueForKey:@"temp"];
关于iOS JSON 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330179/