我知道这是一个愚蠢的问题,但我不知道该怎么做。从此链接 请求的链接可以返回带有 NSURLconnection 的 json 数据吗?我希望有人检查此链接并告诉我这是否可能,因为我是这方面的新手。
编辑:
我尝试使用NSJSONSerialization
- (void)viewDidLoad
{
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.goalzz.com/main.aspx?region=-1&area=6&update=true"]];
connectionData = [[NSURLConnection alloc]initWithRequest:req delegate:self];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
Data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[Data appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *jsonParsingError = nil;
id object = [NSJSONSerialization JSONObjectWithData:Data options:0 error:&jsonParsingError];
if (jsonParsingError) {
NSLog(@"JSON ERROR: %@", [jsonParsingError localizedDescription]);
} else {
NSLog(@"OBJECT: %@", [object class]);
}
}
我在控制台中收到此错误消息:
JSON 错误:操作无法完成。(可可错误 3840。)