我有一點使用JSONKit的反序列化。它正在工作,但我寫的感覺很笨拙。任何人都可以提出一些改進建議:)iPhone - JSONKit - 工作,但我使用它嗎?
//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];
}
好的,謝謝你的建議。我想知道是否有方法從NSDictionary,NSArray然後回到NSDictionary。它似乎應該有某種對象可以爲所有三個做? – shaw2thefloor