2011-11-11 72 views
0

我有一個方法如下使用糾正的Json問題與調用功能

+(NSString *)CorrectJsonForEmptyValues:(NSString *)pasRawJson 
{ 

    NSLog(@"CorrectJsonForEmptyValues"); 
    NSMutableString *tmpJson = [pasRawJson mutableCopy]; 

    [tmpJson replaceOccurrencesOfString:@"[," 
          withString:@"[{\"v\": \"N/A\",\"f\":\"N/A\"}," 
           options:0 
            range:NSMakeRange(0, [tmpJson length])]; 

    [tmpJson replaceOccurrencesOfString:@",," 
          withString:@",{\"v\": \"N/A\",\"f\":\"N/A\"}," 
           options:0 
            range:NSMakeRange(0, [tmpJson length])]; 

    NSString *correctedJson=tmpJson; 
    return correctedJson; 
} 

空值,這樣調用

result = [self performSelector:@selector(CorrectJsonforEmptyvalues:) withObject:result]; 

但是,讓錯誤的函數

2011-11-11 11:11:33.217 HelloWorld10[38833:207] -[Data CorrectJsonforEmptyvalues:]: unrecognized selector sent to instance 0x5725cc0 
2011-11-11 11:11:33.219 HelloWorld10[38833:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Data CorrectJsonforEmptyvalues:]: unrecognized selector sent to instance 0x5725cc0' 

如果任何人都可以請提供一個解決方案,這將是有益的。 在此先感謝。

回答

5

您已聲明CorrectJsonForEmptyValues:作爲類方法,通過+而不是-開始其聲明/定義。因此,您可以在類對象上調用它,而不是在類的實例上調用它。如果你的類被命名爲Data,例如,你怎麼稱呼它是這樣的:

result = [Data CorrectJsonForEmptyValues:result]; 

順便說一句,你不應該用大寫字母開頭的方法名。

1

你可以調用函數如下

 [self CorrectJsonForEmptyValues:result]; 

並符合下列替換 '+' ' - '

+(NSString *)CorrectJsonForEmptyValues:(NSString *)pasRawJson{