Created
April 9, 2014 02:08
-
-
Save itoz/10219299 to your computer and use it in GitHub Desktop.
[objc][memo] BundleのJSONを読み込んでNSArrayにする ref: http://qiita.com/itoz/items/62a45eca3d59e0d60ded
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
//------------------------------ | |
// JSONを読み込む | |
//------------------------------ | |
NSError *error0 = nil; | |
NSBundle *bundle = [NSBundle mainBundle]; | |
NSString *path = [bundle pathForResource:@"local" ofType:@"json"]; | |
NSString *jsonString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error: &error0]; | |
NSData *jsonData = [jsonString dataUsingEncoding:NSUnicodeStringEncoding]; | |
if(error0){NSLog(@"よみこみえらー");} | |
//------------------------------ | |
// NSArray に変換 | |
//------------------------------ | |
NSError *error1 = nil; | |
NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData | |
options:NSJSONReadingAllowFragments | |
error:&error1]; | |
if(error1){NSLog(@"ぱーすえらー");} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment