I have a little bit of deserialisation using JSONKit. It is working, but what I have written feels pretty clunky. Can anyone suggest some improvements please 🙂
//call web service with url and staff id
NSString *result = [MobileAppDelegate webServiceExecuteGetSingleWithId:StaffId
atUrl:@"XXXXXXXX"];
//create NSDictionary from JSON return type
NSDictionary *items = [result objectFromJSONString];
NSArray *ar = (NSArray*)[items objectForKey:@"SummaryJsonResult"];
for(int i = 0; i < [ar count]; i++){
NSDictionary *tmpDict = (NSDictionary*)[ar objectAtIndex:i];
AlertItem *tmpItem = [[AlertItem alloc] init];
tmpItem.Description = [tmpDict objectForKey:@"Description"];
tmpItem.NumItems = [tmpDict objectForKey:@"ItemCount"];
tmpItem.ModuleGroup = [tmpDict objectForKey:@"ModuleGroup"];
tmpItem.StaffID = [tmpDict objectForKey:@"StaffID"];
tmpItem.status - [tmpDict objectForKey:@"Status"];
[array addObject: tmpItem];
[tmpItem release];
}
That’s essentially how you have to do it. You can clean things up a little bit:
Use a
for-inloop:Refactor creating an
AlertItemfrom the dictionary into a factory method: