0

我有两个 UItextFields,userNameTextField 和 passwordTextField 以及一个 UIbutton 连接。我想知道用户在 userNametextField 和 passwordTextField 中输入的内容,请问我该怎么做?感谢您的回答。

#pragma mark - User auhtentification
-(IBAction)userAuthentificate{
    BOOL loginValid = YES;
    BOOL passwordValid = YES;   // Not specified yet

    // contrioll d'interfac__ on test login et password
    if (loginValid && passwordValid) {

    NSString *jsonRequest = @"{\"login\":\"Samir\",\"password\":\"test\",\"mail\":\"test@gmail.com\"}";


        //  NSString *jsonRequest = @"{\"login\":\"Samir\",\"password\":\"test\",\"mail\":\"samir@gmail.com\",\"editor\":\"1\"}";


        NSString *request_url =@"http:.../register"; // Url WS
        NSURL *url = [NSURL URLWithString:request_url];
        self.currentRequest = [ASIFormDataRequest requestWithURL:url];
        currentRequest.delegate =self;
        NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
        [self.currentRequest appendPostData:requestData];
        [self.currentRequest setRequestMethod:@"POST"];

        [self.currentRequest startSynchronous];
    }
}
4

3 回答 3

2

你可以把这样的东西放在你的jsonRequest字符串的地方(代码使用SBJson框架):

NSDictionary *container = [[NSDictionary alloc] initWithObjectsAndKeys:
                            [loginTextField text], @"login",
                            [passwordTextField text], @"password",
                            [mailTextField text], @"mail"];

NSString *jsonString = [container JSONRepresentation];
// don't forget to release container if not using ARC AFTER creating the NSData object
于 2012-05-14T09:30:14.347 回答
1

简单的字符串替换怎么样?

NSString *jsonRequest = [NSString stringWithFormat:@"{\"login\":\"%@\",\"password\":\"%@\",\"mail\":\"%@\"}", userNameTextField.text, passwordTextField.text, emailtextField.text];
于 2012-05-14T09:27:54.970 回答
0

采用

NSString *jsonRequest = [NSString stringWithFormat:@"{\"login\":\""%@"\",\"password\":\""%@"\",\"mail\":\"test@gmail.com\"}",userNameTextField.text,passwordTextField.text];
于 2012-05-14T09:29:31.330 回答