下面是从 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/