Checking null value

Discussion in 'iOS Programming' started by erdinc27, Sep 22, 2016.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #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 ?
     
  2. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #2
    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.
     
  3. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #3
    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.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    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.
     

Share This Page