Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
I got Json data from webservice. But i have a problem. The data comes like this
Code:
{
    hediyeCom = "(null)";
....
....
}
i check null value like this
Code:
 if ([giftDictionary objectForKey:@"hediyeCom"] == [NSNull null]) {
NSLog(@"NULL");
    }
But it doesnt fall down in if state. How can i check the null value ?
 
I got Json data from webservice. But i have a problem. The data comes like this
Code:
{
    hediyeCom = "(null)";
....
....
}
i check null value like this
Code:
 if ([giftDictionary objectForKey:@"hediyeCom"] == [NSNull null]) {
NSLog(@"NULL");
    }
But it doesnt fall down in if state. How can i check the null value ?

Depending on the JSON response you're getting, there are a couple of possibilities here. First, the `hediyeCom` key might not even be in the response, in which case you'd be getting back a nil value for that key, not a NSNull object (in this case, giftDictionary[@"hediyeCom"] == nil instead of giftDictionary[@"hediyeCom"] == [NSNull null]). If the excerpt you've shown above is the actual JSON response, the value might be the literal string "(null)". I'd try adding a
Code:
NSLog(@"%@",giftDictionary[@"hediyeCom"]);
call or adding a breakpoint right before the if statement to see exactly what you're working with.
 
Depending on the JSON response you're getting, there are a couple of possibilities here. First, the `hediyeCom` key might not even be in the response, in which case you'd be getting back a nil value for that key, not a NSNull object (in this case, giftDictionary[@"hediyeCom"] == nil instead of giftDictionary[@"hediyeCom"] == [NSNull null]). If the excerpt you've shown above is the actual JSON response, the value might be the literal string "(null)". I'd try adding a
Code:
NSLog(@"%@",giftDictionary[@"hediyeCom"]);
call or adding a breakpoint right before the if statement to see exactly what you're working with.

thank you for your response buddy. It was an actual response actually and the response was not a null as you said it was a string "(null)" so i can handle it now. Thank you for the help.
 
That is not a standard JSON representation of null. If you have access to the server authors you might ask them the reason for not getting back a standard null.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.