Skip to content

Instantly share code, notes, and snippets.

@yuxiangq
Last active August 29, 2015 14:07
Show Gist options
  • Save yuxiangq/e1e062116bfc1f948166 to your computer and use it in GitHub Desktop.
Save yuxiangq/e1e062116bfc1f948166 to your computer and use it in GitHub Desktop.
p_GetJsonContent
-(void)p_GetJsonContent{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"https://raw.githubusercontent.com/lovekarri/exercise/master/content.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSString *content=[NSString stringWithContentsOfURL:filePath encoding:NSUTF8StringEncoding error:nil];
QModel *model=[QModel objectFromDictionary:[content objectFromJSONString]];
self.Sections=model.Section;
}];
}];
[downloadTask resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment