Checking a null value in Objective-C that has been returned from a JSON string

前端 未结 15 1594
北海茫月
北海茫月 2020-11-30 20:34

I have a JSON object that is coming from a webserver.

The log is something like this:

{          
   \"status\":\"success\",
   \"Us         


        
15条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 21:08

    I tried a lot method, but nothing worked. Finally this worked for me.

    NSString *usernameValue = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"usernameKey"]];
    
    if ([usernameValue isEqual:@"(null)"])
    {
         // str is null
    }
    

提交回复
热议问题