Last active
August 29, 2015 14:07
-
-
Save yuxiangq/e1e062116bfc1f948166 to your computer and use it in GitHub Desktop.
p_GetJsonContent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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