我正在开发一个应用程序,我现在正在使用MAMP PRO从数据库中获取JSON数据。这是代码:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.1.8/ArabLineDatabase/GetSocialNetworkCount.php"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.8/ArabLineDatabase/GetSocialNetworkCount.php"]];
JsonData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
NSLog(@"Connecting.....GetSocialNetworkCount.M");
}
else
{
NSLog(@"Can't connect.....GetSocialNetworkCount.M");
}
问题是无论何时没有互联网或我关闭服务器因此无法访问我的应用程序崩溃,并且我收到JSON Data is nil
如何阻止该错误的错误?
答案 0 :(得分:0)