For json answer, I removed null values like this
NSArray *arr = [NSArray arrayWithObjects:_IDArray, _TypeArray, _NameArray, _FlagArray, nil]; for (int i=0; i<_integer; i++) { // My json response assigned to above 4 arrayes //Now remove null values //Remove null values for (int j=0; j<arr.count; j++) { for (NSMutableArray *ar in arr) { if ([[ar objectAtIndex:i] isKindOfClass:[NSNull class]] || [[ar objectAtIndex:i] isEqualToString:@"null"]) { [ar addObject:@""];//Add empty value before remove null value [ar removeObjectAtIndex:i]; } } } }
Now delete the empty values
// Add arrays to a mutable array to remove empty objects
NSArray *marr = [NSArray arrayWithObjects:_IDArray, _TypeArray, _NameArray, _FlagArray, nil]; //Remove empty objects from all arrays for (int j=0; j<marr.count; j++) { for (int i=0; i<[[marr objectAtIndex:j] count]; i++) { if ([[[marr objectAtIndex:j] objectAtIndex:i] isEqualToString:@""]) { [[marr objectAtIndex:j] removeObjectAtIndex:i]; } } }
source share