-2

我已使用以下代码链接到 API,但没有收到响应。没有显示错误,但我从状态、错误和用户变量中得到一个空值。我已经重新检查过,我在 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];
}
4

1 回答 1

1

在你的代码中试试这个。

     NSURL *url = [[NSURL alloc]initWithString:[NSString stringWithFormat:@"%@email=%@&password=%@&action=signin",MainURL, _EmailField.text,_PasswordField.text]];
于 2013-11-12T10:58:32.860 回答