2013-02-08 109 views
1

有人可以帮我解决该警告吗?未找到实例方法'-objectFromJSONString'(返回类型默认为'id')

警告:

Instance method '-objectFromJSONString' not found (return type defaults to 'id') 

代码:

- (void)checkVersion { 
    NSString *version = @""; 

    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=<Your app ID>"]; 
    ASIHTTPRequest *versionRequest = [ASIFormDataRequest requestWithURL:url]; 
    [versionRequest setRequestMethod:@"GET"]; 
    [versionRequest setDelegate:self]; 
    [versionRequest setTimeOutSeconds:150]; 
    [versionRequest addRequestHeader:@"Content-Type" value:@"application/json"]; 
    [versionRequest startSynchronous]; 

    NSString* jsonResponseString = [versionRequest responseString]; 

    // --> ERROR NEXT LINE 
    NSDictionary *loginAuthenticationResponse = [jsonResponseString objectFromJSONString]; 

    NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"]; 

    for (id config in configData) 
    { 
     version = [config valueForKey:@"version"]; 
    } 

    //Get Current Version 
    NSString *currentVersion=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; 
    //Check your version with the version in app store 
    if (![version isEqualToString:currentVersion]) 
    { 
     UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"New Version" 
                 message:@"Download it!" delegate:self 
               cancelButtonTitle:@"Cancel" 
               otherButtonTitles:@"Download", nil] autorelease]; 
     [alert show]; 
    } 
} 
+2

您包括JSONKit? – Jeremy 2013-02-08 21:15:31

+1

错误?如果“返回类型默认为id”,那么它很可能是一个警告。 – 2013-02-08 21:19:38

+0

是的,这是一个警告!我添加了JSON类,但继续警告。 – 2013-02-08 21:20:49

回答

3

您需要的JSONKit头文件导入到目前正使用它的文件:

#import "JSONKit.h" 
+0

但为什么它也可以在不导入JSONKit头文件的情况下工作? – why 2013-02-26 06:40:25

+0

因为编译器在这种情况下猜对了 - 它确实返回了id。 ( - (id)objectFromJSONString;) – escrafford 2013-02-26 17:41:52

相关问题