【发布时间】:2013-08-19 12:31:56
【问题描述】:
当我运行我的应用时,如果没有互联网连接,它会直接终止我的应用并显示此消息。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil
- (void)viewDidLoad
{
response = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/jsonTest.php"]];
NSError *parseError = nil;
jsonArray = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:&parseError];
jsonArray1 = [[NSMutableArray alloc] init];
for(int i=0;i<[jsonArray count];i++)
{
...
..
.
}
}
我已尝试使用下面的代码来显示警报视图,但没有显示任何内容,我做错了什么吗?
-(void)uploadRequestFailed:(NSJSONSerialization *)request
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"No internet connection" message:@"Please check the internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
【问题讨论】:
-
我认为您的应用程序终止了,因为您在没有网络连接的情况下将
nil数据传递给NSJSONSerialization。 -
没有网络时你的响应为零。
标签: ios nsjsonserialization nserror