I have fetched the JSON data i want to store all the information like in a Book class object book and the use them by book.title etc. I am using following code
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=350&counties-selected=Vest-Agder,Aust-Agder"]];
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];
NSDictionary *dictOne = [results objectAtIndex:0];
/*
NSArray *activitiesArray = [dictOne objectForKey:@"events"];
NSDictionary *dictTwo = [activitiesArray objectAtIndex:0];
NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
*/
appDelegate.books = [[NSMutableArray alloc] init];
NSArray *activitiesArray = [dictOne objectForKey:@"events"];
NSDictionary *dictTwo = [acti开发者_如何学GovitiesArray objectAtIndex:0];
NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
I want to do like this store the data in an array but its not working
NSArray *results = [parser objectWithString:json_string error:nil];for (int i=0; i<[results count]; i++) {
Book *aBook = [[Book alloc] initWithDictionary:[results objectAtIndex:i]];
[appDelegate.books addObject:aBook];
[aBook release];
}
精彩评论