json - ios: Compare NSString to "<null>" not working -
i consuming web service returns json. 1 of values "< null >"
.
when run follwoing code if statment still executed when not suppposed to.
any reason why?
nsdictionary *location = [dictionary valueforkey:@"geolocation"]; //get product name nsstring *latitude = [location valueforkey:@"latitude"]; nslog(@"%@", latitude); nsstring *longitude = [location valueforkey:@"longitude"]; if (![latitude isequal: @"<null>"] && ![longitude isequal: @"<null>"]) { nslog(@"%d", i); cllocationcoordinate2d coordinate; coordinate.longitude = [latitude doublevalue]; coordinate.longitude = [longitude doublevalue]; [self buildmarketslist:coordinate title:title subtitle:nil]; //build browse list product }
i consuming web service returns json. 1 of values "< null >"
aha. 2 possibilities:
i. json doesn't contain latitude , longitude information. in case, keys them aren't present in dictionary you're getting back, in fact obtaining nil
(or null
) pointer. messaging nil
returns zero, both conditions fire (due negation applied). try instead:
if (latitude != nil && longitude != nil)
and never rely on description of object.
ii. json contains null
values, , json parser you're using turns null
[nsnull null]
, , in turn you're trying compare string against nsnull
. in case, try this:
if (![latitude isequal:[nsnull null]] && ![longitude isequal:[nsnull null]])
Comments
Post a Comment