0

I got data from JSON and put in to an array. I successfully set cell images with it, now I'm trying to set names.

Apparently, some names are empty, or to be exactly, contain following:

"name": null, (pasted from browser JSON viewing)

So, when compiler get to this, it throw an exception with following:

name is = <null>
[NSNull length]: unrecognized selector sent to instance 0x324586a0

I even made some safe checking, but apparently its not working:

NSString *nameString = [self.dataDict valueForKey:@"name"];
           if (nameString){
           nameLabel.text = nameString;
           }

I don't mind if name would be null, but app just crash. How to fix that?

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
  • Write Below Code. if([nameString length] > 0){ nameLabel.text = nameString; }else{ nameLabel.text = @"Print Anything you want or pass Blank"; } – Renish Dadhaniya Feb 28 '15 at 13:22
  • When you Ask any question first think about solutions of it and do some googling......... – Renish Dadhaniya Feb 28 '15 at 13:23
  • @RenishDadhaniya your answer is wrong (error is [NSNull length]: unrecognized selector sent to instance 0x13cf6c8). answer any question first think about is your solution correct... – Evgeniy Kleban Feb 28 '15 at 16:31

0 Answers0