ran*_*omx 0 objective-c ios5 xcode4.3
我有一个API返回一个JSON编码的数据字符串,返回一个实数或"null"作为一个值.只要JSON包含数字或字符串值,一切都按预期工作.如果key:value对值为null,则下面的代码崩溃.
当从SBJSON获取NULL时,如何正确测试NSDictionary objectForKey?
当API 为filetype返回null时,下面的代码在if()行崩溃.
我的Objective-C代码尝试测试期望值:
if (1 == [[task valueForKey:@"filetype"] integerValue]) {
// do something
} else {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
API JSON输出:
{"tclid":"3","filename":null,"filetype":null}
Run Code Online (Sandbox Code Playgroud)
NSDictionary的NSLog()输出是:
task {
filename = "<null>";
filetype = "<null>";
tclid = 3;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |