NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"CRN_JSON"
ofType:@"json"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
data = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://properfrattire.com/Classifi/CRN_JSON.json"]];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:YES];
});
运行此代码后,我的数据变量为零。如果您点击链接,您会看到它是一个 JSON 文件。我已经在本地使用这个完全相同的文件运行了该函数,但它无法在给定的 URL 处获取数据而不会出错。