我正在制作一个小型的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'`

是什么导致此异常?为什么即使我指定了NSString,也显示我在这里使用NSCFString?

最佳答案

您已经包含JSONKit.h,但是您忘记在项目中包含JSONKit.m。它可以很好地编译,但是在运行时没有实现。

10-08 02:24