I am a begginer in iOS and i've got a little problem. I don't know how to get a data from JSONObject for the index i, and for the key x.
Just below, there is my code
-(NSMutableArray*)getAll{
NSMutableArray* liste;
dispatch_queue_t downloadQueue = dispatch_queue_create("Get All Offers", NULL);
dispatch_async(downloadQueue, ^{
NSData *result = [self executePostCall];
dispatch_async(dispatch_get_main_queue(), ^{
id strResult=nil;
NSError* error;
strResult = [NSJSONSerialization JSONObjectWithData:result options:0 error:&error];
for(int cpt=0; cpt>[strResult count];cpt++)
{
[liste addObject:[NSMutableArray new]];
// ERREUR ICI !!!!!!!!!
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"titre"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"srcImage"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"date"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"prix"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"ville"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"categorie"]]];
}
});
});
NSLog(@"liste: %@",liste);
return liste;
}
I tried to get the object with the key (for example "titre") at the line cpt. Can you help me please ?
I think the problem is when i'm doing [[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"titre"]]]; but i don't know how to solve it.
[self executePostCall] is another function which works fine.
Thanks for your help