ios - 如何访问 JSON 数据并将其显示在 XCode Logcat 中,如果响应为空,我想显示警报

标签 ios objective-c json xcode asp.net-web-api

下面是从 Web 获取数据并尝试在 logcat 中显示的示例代码。我在这里 pst 代码。请帮我解决。提前致谢

NSArray *dicAllNetworks = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

NSLog(@"JsonData=%@",dicAllNetworks);

for (NSDictionary *dict in dicAllNetworks)
{
    NSInteger number = [dict[@"UserID"] intValue];
    NSString *UserTypeConst =dict[@"UserTypeConst"];
    NSString *name = dict[@"UserName"];
}

这是回应:

JsonData=[{"UserID":2478,"UserTypeConst":"PQR","UserName":"115005p"}]

如果响应为空

我想显示警报。

最佳答案

      dispatch_async(dispatch_get_main_queue(), ^{

                                                UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Please enter valid UserID and Password" message:@"" preferredStyle:UIAlertControllerStyleAlert];

                                                UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
                                                                     {
                                                                         [alert dismissViewControllerAnimated:YES completion:nil];
                                                                     }];

                                                [alert addAction:ok];
                                                [self presentViewController:alert animated:YES completion:nil];

                                                NSLog(@"Invalide Login Credential.");


                                            });

关于ios - 如何访问 JSON 数据并将其显示在 XCode Logcat 中,如果响应为空,我想显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572575/

相关文章:

iphone 代码 - CGPoint 问题

ios - ScrollView 不滚动

javascript 对象未定义错误

java - Gson解析卡住

ios - Realm = RLMRealm' 没有成员 'setDefaultRealmPath'

ios - 将 4x4 矩阵传递给 glUniformMatrix4fv

ios - 当 iPhone 方向改变时更改 UIViews 位置

c# - 将 JSON 和输入文件传回 Controller MVC 4

ios - 如何在点击PresentationLink (SwiftUI) 时禁用闪烁?

ios - React Native 开发人员菜单未加载