Created
July 1, 2014 17:48
-
-
Save csmobile/55f49d767fb2460a2175 to your computer and use it in GitHub Desktop.
Parse JSON to object
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
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&error];//response object is your response from server as NSData | |
if ([json isKindOfClass:[NSDictionary class]]){ //Added instrospection as suggested in comment. | |
NSArray *yourStaffDictionaryArray = json[@"directory"]; | |
if ([yourStaffDictionaryArray isKindOfClass:[NSArray class]]){//Added instrospection as suggested in comment. | |
for (NSDictionary *dictionary in yourStaffDictionaryArray) { | |
Staff *staff = [[Staff alloc] init]; | |
staff.id = [[dictionary objectForKey:@"id"] integerValue]; | |
staff.fname = [dictionary objectForKey:@"fName"]; | |
staff.lname = [dictionary objectForKey:@"lName"]; | |
//Do this for all property | |
[yourArray addObject:staff]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment