标签:
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?userName=%@&userPwd=%@",BASE_API,Login,_phoneNumTextField.text,_verificationCodeTextFiled.text]]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager POST:URL.absoluteString parameters:nil constructingBodyWithBlock:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { if(IsDictionary(responseObject)){ NSString *str = [responseObject objectForKey:@"status"]; NSDictionary *dic =[self dictionaryWithJsonString:[responseObject objectForKey:@"data"]]; if ([str isEqualToString:@"0"]) { [Util saveResposeDefaults:dic]; MainViewController *mMainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; UINavigationController *mUINavigationController = [[UINavigationController alloc] initWithRootViewController:mMainViewController]; [self presentViewController:mUINavigationController animated:YES completion:nil]; mUINavigationController = nil; }else if ([str isEqualToString:@"2"]){ NSLog(@"密码错误"); }else{ NSLog(@"用户不存在"); } } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"Error: %@", error); }];
-(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString == nil) { return nil; } NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; if(err) { NSLog(@"json解析失败:%@",err); return nil; } return dic; }
标签:
原文地址:http://www.cnblogs.com/wq-gril/p/5112615.html