我使用以下代码链接到API,但我没有收到回复。没有显示错误,但我从状态,错误和用户变量输出null。 我已经重新检查了,我在MainURL变量中使用的URL也是正确的。
NSURL *url = [[NSURL alloc]initWithString:@"%@email=%@&password=%@&action=signin",MainURL, _EmailField.text,_PasswordField.text];
NSError *errors;
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *json = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&errors];
status = json[@"status"];
error = json[@"error"];
user = json[@"user"];
if ([status isEqualToString:@"success"])
{
[self performSegueWithIdentifier: @"LogIN" sender: self];
}
else
{
messages=[[NSString alloc]init];
for (int i=0; i<[error count]; i++)
{
messages=[messages stringByAppendingString:[error objectAtIndex:i]];
messages=[messages stringByAppendingString:@"\n"];
}
UIAlertView *failure=[[UIAlertView alloc]initWithTitle:@"Failure" message:messages delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[failure show];
}
答案 0 :(得分:1)
在您的代码中尝试此操作。
NSURL *url = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"%@email=%@&password=%@&action=signin",MainURL, _EmailField.text,_PasswordField.text]];