我想执行赛格瑞如果登录响应是与响应JSON验证登录
登录响应:
{ “登录”:[{ “参数userid”: “12”, “名称”:” (abc)“}]}
我该如何验证它?
下面是我提取响应的代码。
-(IBAction)loginbutton:(id)sender {
NSString *post = [[NSString alloc] initWithFormat:@"email==%@&pass==%@",self->email.text,self->passwrd.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:@"URL"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(@"Login response: is %@",str); //getting response
}
解析JSON响应,并期待在您需要验证的任何值。 Objective-C中有无数解析JSON的例子。 – rmaddy
@rmaddy我已经提到了我在问题中的回答,我想验证该问题以继续登录。 –
没错。我告诉你你必须做什么。您需要解析JSON并从中获取所需的值。尝试使用您可以找到的无数现有示例来解析JSON。然后根据需要更新您的问题,一旦你到达那里。 – rmaddy