Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2015 14:00
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 3lvis/a5c718bf4855343b899a to your computer and use it in GitHub Desktop.
Save 3lvis/a5c718bf4855343b899a to your computer and use it in GitHub Desktop.
Returns an array or dictionary from a .json file
+ (id)JSONObjectWithContentsOfFile:(NSString*)fileName
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:[fileName stringByDeletingPathExtension]
ofType:[fileName pathExtension]];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
if (error != nil) return nil;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment