A9628298AF2F97B5E073C680D9D5DC85 Apps King Technologies

Tuesday 25 February 2014




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__);


1 comment: