我在我的应用程序中实现了 Web 服务。我的方式很典型。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Web Service xxx,yyy are not true data
NSString *urlString = @"http://xxx.byethost17.com/yyy";
NSURL *url = [NSURL URLWithString:urlString];
dispatch_async(kBackGroudQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: url];
[self performSelectorOnMainThread:@selector(receiveLatest:) withObject:data waitUntilDone:YES];
});
return YES;
}
- (void)receiveLatest:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSString *Draw_539 = [json objectForKey:@"Draw_539"];
....
控制台错误信息:
*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“数据参数为零”
当我的 iphone 连接到 Internet 时,该应用程序成功运行。但是,如果它断开与 Internet 的连接,应用程序将在NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
您能告诉我如何处理此错误时崩溃吗?有NSError
帮助吗?