检查Objective-C中从JSON字符串返回的空值 [英] Checking a null value in Objective-C that has been returned from a JSON string
问题描述
我有一个 JSON 对象来自网络服务器。
I have a JSON object that is coming from a webserver.
日志是这样的:
{
"status":"success",
"UserID":15,
"Name":"John",
"DisplayName":"John",
"Surname":"Smith",
"Email":"email",
"Telephone":null,
"FullAccount":"true"
}
注意电话进来了如果用户没有输入,则为null。
Note the Telephone is coming in as null if the user doesn't enter one.
将此值分配给 NSString
时,在 NSLog
它出现为< null>
When assigning this value to a NSString
, in the NSLog
it's coming out as <null>
I我正在分配这样的字符串:
I am assigning the string like this:
NSString *tel = [jsonDictionary valueForKey:@"Telephone"];
检查此< null> $的正确方法是什么c $ c>价值?它阻止我保存
NSDictionary
。
What is the correct way to check this <null>
value? It's preventing me from saving a NSDictionary
.
我尝试使用条件 [myString长度]
和 myString == nil
和 myString == NULL
此外,iOS文档中哪个地方最适合阅读?
Additionally where is the best place in the iOS documentation to read up on this?
推荐答案
< null>
是NSNull单例记录的方式。所以:
<null>
is how the NSNull singleton logs. So:
if (tel == (id)[NSNull null]) {
// tel is null
}
(单身因素存在,因为你无法添加 nil
到集合类。)
(The singleton exists because you can't add nil
to collection classes.)
这篇关于检查Objective-C中从JSON字符串返回的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!