我有一些看起来像这样的代码:
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSArray *arrRequests = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:nil];
// Loop through the array and generate the necessary annotation views
for (int i = 0; i<= arrRequests.count - 1; i++)
{
//now let's dig out each and every json object
NSDictionary *dict = [arrRequests objectAtIndex:i];
NSString *is_private = [NSString
stringWithString:[dict objectForKey:@"is_private"]];
...
它在 is_private 的值为 1 或 0 时起作用,但如果它为 null,则会在此行出现异常并崩溃:
NSString *is_private = [NSString stringWithString:[dict objectForKey:@"is_private"]];
有没有办法检查它是否不为空或处理它以便能够将 nil 放入 NSString *is_private 变量中?
谢谢!