There are two approaches here. Either add an -initWithJSONString:
method to your data objects and pass the JSON directly to them for break-down, or add an -initWithAttributes:
method that takes a dictionary that you get from parsing the JSON. For example:
- (id)initWithAttributes:(NSDictionary *)dict
{
// This is the complicated form, where you have your own designated
// initializer with a mandatory parameter, just to show the hardest problem.
// Our designated initializer in this example is "initWithIdentifier"
NSString *identifier = [dict objectForKey:MYIdentifierKey];
self = [self initWithIdentifier:identifier];
if (self != nil)
{
self.name = [dict objectForKey:MYNameKey];
self.title = [dict objectForKey:MYTitleKey];
}
return self;
}
Creating an -initWithJSONString:
method would be very similar.