2012-01-09 50 views
0

Im从php脚本中拉出图片的位置,如果没有图片位置,它会在JSON输出中显示位置“null”。这是在我的代码中抛出异常。这里是一个不工作的代码:异常如果没有或<null>

NSString *piclocation = picloc; 
if(piclocation == nil || @"null"){ 

}else{ 
NSString *mutableUrlString = @"https://www.mypage.com/uploads"; 
mutableUrlString = [mutableUrlString stringByAppendingString: piclocation]; 
NSLog(mutableUrlString); 
NSURL *url = [NSURL URLWithString: mutableUrlString]; 
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 
imageView.image = image; 
} 

错误是:终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“* - [NSNull长度]:无法识别的选择发送到实例0x98d5a0” 有什么建议么?

回答

9

您需要稍微纠正一下您的代码。

if (piclocation == (id)[NSNull null] || piclocation.length == 0 || [piclocation isEqualToString:@"null"]) 

我认为这会为你做。

+0

确实可以接受。 – 2012-01-09 07:43:18

+0

谢谢先生。一起来:) – savagenoob 2012-01-09 07:45:40

+0

作品完美赛亚! – Nirav 2013-05-07 05:20:01