objective-c – ObjC / iOS:NSCFString不是NSString?
发布时间:2020-12-16 10:50:50 所属栏目:百科 来源:网络整理
导读:我正在制作一个小型iOS应用程序,它使用ASIHTTPRequest请求一个 JSON文件,我希望它由 JSONKit解析.我正在使用以下代码: - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ // yada yada NSURL *url = [NSURL URLWithString:@"http://localhos
我正在制作一个小型iOS应用程序,它使用ASIHTTPRequest请求一个
JSON文件,我希望它由
JSONKit解析.我正在使用以下代码:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ // yada yada NSURL *url = [NSURL URLWithString:@"http://localhost/file.json"]; // the file is a valid Json ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request setTimeOutSeconds:20]; // Response takes too long on local machine [request startAsynchronous]; } - (void)requestFinished:(ASIHTTPRequest *)request { responseString = [request responseString]; // request type: ASIREQUEST,responseString is declared as NSString NSLog(@"%@ n",[responseString class]); // NSCFString NSDictionary *deserializedData = [responseString objectFromJSONString]; } 但是,我在应用程序运行时看到以下异常: [7646:207] -[NSCFString objectFromJSONString]: unrecognized selector sent to instance 0xdba0000 [7646:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '-`[NSCFString objectFromJSONString]: unrecognized selector sent to instance 0xdba0000'` 可能导致此异常的原因是什么?为什么它显示我在这里使用NSCFString,即使我指定了NSString? 解决方法
你已经包含了JSONKit.h,但是你忘了在项目中包含JSONKit.m.它编译得很好,但实现不是在运行时.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |