我需要从 JSON 下载数据,并将数据分配NSData
给NSOperationQueue
. 这是我的代码:
-(void)parsingInfo {
NSURL *url = [NSURL URLWithString:@"http://someJSON.json"];
NSData *data;
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:downloadQueue completionHandler:^(NSURLResponse* response, NSData* jsonData, NSError* error){
if(error)
{
// Error Downloading data
NSLog(@"Error");
}
else
{
data = jsonData;
}
}];
if (data) {
NSError *error;
NSDictionary *JSONDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
application = [JSONDic objectForKey:@"Applications"];
NSArray *featured = [JSONDic objectForKey:@"Featured"];
NSDictionary *dict2;
dict2 = [featured objectAtIndex:0];
} else {
NSLog(@"Error, no data!");
}
}