2011-11-11 71 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{