'NSInvalidArgumentException',原因:' - [SBJsonParser objectWithString:error:]:无法识别的选择器发送到实例0x6695330'

时间:2012-01-10 14:13:52

标签: iphone ios json sbjson

在我的iphone应用程序上创建登录视图时,我遇到了这个错误:

'NSInvalidArgumentException', reason: '-[SBJsonParser objectWithString:error:]:
    unrecognized selector sent to instance 0x6695330'

它来自这条线:

NSDictionary *results = [parser objectWithString:json_string error:nil];

从这个方法:

+ (BOOL)loginWithUsername:(NSString *)username password:(NSString *)password
{
    NSString *urlString = [NSString stringWithFormat:@"%@login3", ROSE_ROOT_URL];
    NSURL *url = [NSURL URLWithString:urlString];


    NSString *requestString = [NSString stringWithFormat:@"&mobile=1&username=%@&password=%@", username, password];


    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[NSData dataWithBytes:[requestString UTF8String] length:[requestString length]]];

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

    [request release];
    // parse the JSON response into an object
    // Here we're using NSArray since we're parsing an array of JSON product objects
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSDictionary *results = [parser objectWithString:json_string error:nil];

    [json_string release];
    [parser release];


    //  NSDictionary *results = [RoseFetcher fetch:request]; 
    //  [request release];

    if ([[results objectForKey:@"password"] intValue] == 0)
        return NO;

    return YES;
}

非常感谢任何帮助或解释。

1 个答案:

答案 0 :(得分:3)

根据documentation for SBJsonParser,它没有名为-objectWithString:error:的方法 - 这一观点在运行时得到了您的发现的证实。尝试向其发送 会回复的消息,例如-objectWithString: