json parsing using NSJSONSerialization (inbuilt method in objective c)
make a request and get response data then ----
NSData *responseData = [request responseData];
NSError * error;
NSMutableDictionary * json=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
// NSLog(@"%@",json);
NSArray * arrayTemp=[json valueForKey:@"categorylist"];
for (int i = 0; i < [arrayTemp count]; i++)
{
NSMutableDictionary *dict =[[NSMutableDictionary alloc]initWithDictionary:[arrayTemp objectAtIndex:i]];
[dict setObject:[NSNull null] forKey:@"categoryImage"];
[arrMainCategory insertObject:dict atIndex:i];
}
Parse your json by this way-----
NSURL * url=[NSURL URLWithString:@"http://s42sport.com/polarice/json/games.json"];
NSData * data=[NSData dataWithContentsOfURL:url];
NSError * error;
NSMutableDictionary * json=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"%@",json);
NSArray * array1=[json valueForKey:@"c"];
NSLog(@"%@",array1);
To print function name and values for a method in class:
nslog(@" %@",__FUNCTION__);
Good!!!
ReplyDelete