Iphone 在JSON中发布用户名和密码

Iphone 在JSON中发布用户名和密码,iphone,ios,json,web-services,url,Iphone,Ios,Json,Web Services,Url,我有一个web服务,我正在使用一个url,例如 //myurl/index.jsp?user_name=bob&user_pwd=new 如您所见,用户名已设置为“bob”,密码为“new”。该站点在输入时提供此json文件 [{"success":"1"}] 如何在xcode上实现它,当用户输入“bob”作为用户名和“new”作为密码时,它应该指向下一个控制器。我怎样才能做到这一点 我遵循了这一点,虽然不完全一样,但你是如何做到这一点的。谢谢。使用导航控制器并将您的view con

我有一个web服务,我正在使用一个url,例如

//myurl/index.jsp?user_name=bob&user_pwd=new
如您所见,用户名已设置为“bob”,密码为“new”。该站点在输入时提供此json文件

[{"success":"1"}]
如何在xcode上实现它,当用户输入
“bob”
作为用户名和
“new”
作为密码时,它应该指向下一个控制器。我怎样才能做到这一点


我遵循了这一点,虽然不完全一样,但你是如何做到这一点的。谢谢。

使用导航控制器并将您的view controller设置为rootViewController。然后,在用户输入凭据后,将新的视图控制器推送到导航堆栈上

从json响应中获取success的值。如果它等于1,则按下下一个控制器,否则不执行任何操作。

在下面的代码中,您可以通过
GET
POST
方法传递数据…使用任何一种方法(如您所愿)

登录后数据

    NSString *soapMsg = [NSString stringWithFormat:@"&data={\"LoginUser\":[{\"UserName\":\"%@\",\"Password\":\"%@\"}]}",firstname.text, password.text];

    NSHTTPURLResponse *response;
    NSData *myRequestData = [ NSData dataWithBytes: [ soapMsg UTF8String ] length: [ soapMsg length ] ];
    NSString *postLength = [NSString stringWithFormat:@"%d", [myRequestData length]];
    NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://myurl/index.jsp"]];

    [request setHTTPMethod: @"POST" ];
    [request setHTTPBody: myRequestData ];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody: myRequestData];

    NSURLConnection *myConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
接收和使用json数据

 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        NSString *responseString = [[NSString alloc] initWithData:WebXmlData encoding:NSUTF8StringEncoding];
        NSDictionary *results = [responseString JSONValue];
        BOOL success = [[results objectForKey:@"success"] boolValue];

        if (success) {
             ViewController *viewController =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
             [self.navigationController pushViewController:viewController animated:YES];    
        }


    }

不完全是你想要的答案,但这更多的是一个建议,你应该使用什么。 我使用网络进行相关活动。 它们有很好的文档,并且非常易于使用(使用块)


YourAfHttpClientExtension正在扩展AFHttpClient,并添加了一个共享实例的调用方法,并使用Baseur实现了initWithBaseUr:

我已经实现了一个替代方案,但我需要应用程序将用户名和密码发布到webservice url并检查它是否匹配,如果匹配,使用导航控制器推到下一个控制器这是您的问题。您可以检查返回的JSON,并在回答为成功时按下下一个视图控制器。您面临什么问题?您尝试了什么?实例不应该以大写字母开头。我有点困惑,您是否将第一组代码放在viewdidload方法中,将第二组代码放在我的signin button方法中?太棒了,谢谢,但我如何为登录按钮创建一个方法,我很困惑创建按钮与is方法…以及在按钮方法中调用sendRequest方法您只需调用**sendRequest**方法:)使用viewDidload或按钮操作方法…谢谢:)
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        NSString *responseString = [[NSString alloc] initWithData:WebXmlData encoding:NSUTF8StringEncoding];
        NSDictionary *results = [responseString JSONValue];
        BOOL success = [[results objectForKey:@"success"] boolValue];

        if (success) {
             ViewController *viewController =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
             [self.navigationController pushViewController:viewController animated:YES];    
        }


    }
NSDictionary *paramsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"user",@"client_id",@"password",@"new", nil];

    [[YourAFHttpClientExtenstion sharedInstance] postPath:LOGIN_PATH parameters:paramsDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //handle success

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       // handle error.
    }];