Skip to content

Instantly share code, notes, and snippets.

@itoz
Created April 9, 2014 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itoz/10219299 to your computer and use it in GitHub Desktop.
Save itoz/10219299 to your computer and use it in GitHub Desktop.
[objc][memo] BundleのJSONを読み込んでNSArrayにする ref: http://qiita.com/itoz/items/62a45eca3d59e0d60ded
//------------------------------
// 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