如何在注册页面中进行JSON解析

时间:2013-01-14 09:47:24

标签: iphone ios objective-c

我在JSON解析中遇到麻烦。当我完成代码并运行它时,就会出现问题:

  

选择器'show alert:with message'。

没有已知的类方法

以下是我的代码:

if (!isValid) {
    [AppDelegate showAlert:@"Alert!" withMessage:strMessage];
}
return isValid;



}

-(void)registerUser{
[Loading startLoading:YES];
NSString *urlString = [NSString stringWithFormat:@"URL=//%@",Access_Token];
//username, password, name, email, country
NSString *parameter = [NSString stringWithFormat:@"firstname=%@&lastname=%@email=%@&username=%@&password=%@&confirmpassword=@",fnameField.text,lnameField.text,eamilField.text,unameField.text,passField.text,cpassField];
NSConnection *conn = [[NSConnection alloc] initWithDelegate:self];
[conn sendRequest:urlString withParaMeter:parameter withMethod:@"POST" withTag:1];
[conn startAsynchronousRequest];


}



-(void)NSConnection:(NSConnection*)conn didFailWithError:(NSError*)error withTag:(int)tag{
NSLog(@"error is:- %@",[error description]);



}





-(void)NSConnection:(NSConnection*)request didSuccessWithItems:(NSDictionary*)dicData withData:(NSData*)data withTag:(int)tag{
NSLog(@"all data is:- %@",dicData);
int returnCode = [[dicData valueForKeyPath:@"process.returncode"] intValue];
NSString *strMessage = @"";
returnCode = 0;


switch (returnCode) {
    case 0:
        break;
    case 1:
        strMessage = @"User not logged in/process Id not available.";
        break;
    case 2:
        strMessage = @"Invalid parameters passed.";
        break;
    case 3:
        strMessage = @"Access token doesn't exist.";
        break;
    default:
        strMessage = @"User name allready exist.";

        break;
}
[AppDelegate showAlert:@"Alert!" withMessage:strMessage];
[Loading stopLoading];
[self.navigationController popViewControllerAnimated:YES];

请帮帮我。

2 个答案:

答案 0 :(得分:1)

那是因为你试图在对象AppDelegate上调用该方法

然而,AppDelegate类没有实现它。

因此错误。确保它已实施。

答案 1 :(得分:0)

此问题的两次机会

  1. 您未在showAlert: withMessage:
  2. 中声明@interface方法签名
  3. 您可以将其声明为实例方法,使用类名称调用它。
  4. <强>修正:

    1. @interface
    2. 中声明方法签名
    3. 将您的方法定义为Class方法,或者使用您的app delegate的实例
    4. 调用它