ios - 发送用户名和密码后收到服务器响应,但我无法验证登录页面中的响应?

标签 ios objective-c

我在发送用户名和密码后收到了服务器的响应,但我无法在登录页面中验证响应。

我收到以下回复。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject)
{
    NSLog(@"String%@",urlStr);
    _responceString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];

    NSError *localError = nil;
    if ([_responceString isEqual:@"fail"]) {
        NSLog(@"Do Nothing");
    } else {
        NSDictionary *studData = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&localError];
        NSLog(@"response == %@", studData);

    _userDetailsString = [studData valueForKey:@"category"];
    _messageArray=[_userDetailsString valueForKey:@"Message"];
    _usernameArray=[_userDetailsString valueForKey:@"First_Name"];
    _resultArray=[_userDetailsString valueForKey:@"result"];





       //  _resultArray = [[studData valueForKey:@"category"] valueForKey:@"result"];

         NSLog(@" value is %@", _resultArray);


if ([_resultArray isEqualToString:@"Success"]) {
                 NSLog(@"response == %@", _resultArray);




          [self.activityIndicatorView stopAnimating];
             _objHomeviewcontroller=(HomeViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

                [self.navigationController pushViewController:_objHomeviewcontroller animated:YES];

         }
         else
         {
             [self.activityIndicatorView stopAnimating];

             UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert" message: @"invalid data" preferredStyle:UIAlertControllerStyleAlert];
                              [alertController addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                                  [self dismissViewControllerAnimated:YES completion:nil];
                              }]];

                            [self presentViewController:alertController animated:YES completion:nil];


         }

响应:

response == {
    category =     (
                {
            "First_Name" = Sahithi;
            "Last_Name" = L;
            "branch_id" = "05/10/2018 13:11:27  PM";
            result = Success;
            roles = Parent;
        }
    );
}

最佳答案

看看这是否有帮助。您正在寻找结果属性。如果它等于Success,您可以移动到下一个 View Controller 。

If( [[[[studData valueForKey:@"category"] firstObject] objectForKey:@"result"] isEqualToString: @"Success"]) {

    // goto the next view controller
    _objHomeviewcontroller=(HomeViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

    [self.navigationController pushViewController:_objHomeviewcontroller animated:YES];

} else { // goto another view controller}

关于ios - 发送用户名和密码后收到服务器响应,但我无法验证登录页面中的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51230328/

相关文章:

iphone - key 的值为 nil。为什么?

objective-c - 有没有办法(在构建时)判断我的 10.9 应用程序是否可以在 10.8 上运行?

ios - 从 safari 移动设备中的控制台打开链接

iphone - iOS : How to make TableView not to fill the height?

ios - 在我的 UITableView 中选择一个单元格时,选择似乎是随机的

iphone - 选择时 Xcode UITableView 行未突出显示

objective-c - CGImageRef cg = [[UIImage imageNamed : Path] CGImage]; Requires a CGImageRelease(cg)'?

ios - 需要帮助了解自定义 uitableviewcell 初始化

ios - 更新陀螺仪相对于预定义方向的旋转数据?

ios - 尝试在 iPhone 应用程序中播放音频时出错