給予例外JSON數據格式bewlowJSON解析在iPhone應用程序
{ "affectedDate": 1310515200000, "category": "Kultur", "content": "I en festning fra 1600-tallet, ved hjelp av lys, lyd og avansert teknologi møtes de besøkende av synspunkter som kan virker fremmede, de får høre sterke, personlige historier og et mangfold av meninger og stemmer.\n
\n
Vi spør blant annet:\n
Har Sørlandskristendommen ført til maktmisbruk og dobbelmoral? \n
Må barna oppdras i Guds navn for ikke å mangle viktige verdier? og \n
Hvorfor er det bare få som tør å si høyt at de kommuniserer med de døde?\n
\n
â€Himmelen over Sørlandet†er Vest-Agder-museets største utstillingssatsing noensinne, og mer enn 130 mennesker har bidratt.\n
\n
Velkommen til en tankevekkende utstilling!", "eventId": 14569, "imageId": 14597, "large": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_large.jpg", "main": true, "medium": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_gmedium.jpg", "mini": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_pmini.jpg", "small": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_pmedium.jpg", "thumbWide": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_pwide.jpg", "thumbnail": "http://shelf-media.s3.amazonaws.com/7c3f11582bce0b1e153619e436a622da_gsmall.jpg" "title": "Himmelen over Sørlandet" }
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/description.html"]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSDictionary *object = [parser objectWithString:json_string error:nil];
NSArray *results = [parser objectWithString:json_string error:nil];
appDelegate.books1 = [[NSMutableArray alloc] init];
appDelegate.dates =[[NSMutableArray alloc]init];
for (int i=0; i<[results count]; i++) {
NSDictionary *dictOne = [results objectAtIndex:i];
// NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
// NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
// NSLog(@"%@ - %@", [eventDict objectForKey:@"location"]);
NSLog(@"%@ - %@", [dictOne objectForKey:@"affectedDate"]);
NSString*affectedDate=[dictOne objectForKey:@"affectedDate"];
NSString *category=[dictOne objectForKey:@"category"];
// Detail *aBook=[[Detail alloc] initWithDate:affectedDate category:];
}
Wat錯誤你得到,而你解析? – booleanBoy
由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:' - [__ NSCFDictionary objectAtIndex:]:無法識別的選擇器發送到實例0x6e07dd0' – ali
是你解析後得到結果數組中的數據...只要把NSLog和chk它出... – booleanBoy