我有两个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\":\"[email protected]\"}";


        //  NSString *jsonRequest = @"{\"login\":\"Samir\",\"password\":\"test\",\"mail\":\"[email protected]\",\"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];
    }
}

最佳答案

您可以在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

关于objective-c - UItextFields数据到JSON,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10580537/

10-13 04:17