Skip to content

Instantly share code, notes, and snippets.

@itoz itoz/file0.m
Created Apr 9, 2014

Embed
What would you like to do?
[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
You can’t perform that action at this time.