Last active
August 29, 2015 14:00
-
-
Save 3lvis/a5c718bf4855343b899a to your computer and use it in GitHub Desktop.
Returns an array or dictionary from a .json file
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
+ (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