Converting JSON into an Objective-C object
// Retrieve local JSON file called example.json
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"json"];
// Load the file into an NSData object called JSONData
NSError *error = nil;
NSData *JSONData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
// Create an Objective-C object from JSON Data
id JSONObject = [NSJSONSerialization
JSONObjectWithData:JSONData
options:NSJSONReadingAllowFragments
error:&error];
No comments:
Post a Comment