gpt4 book ai didi

ios - 验证登录表单,我正在使用 NSString?

转载 作者:行者123 更新时间:2023-11-29 03:20:50 24 4
gpt4 key购买 nike

编辑请参阅下面的最终代码!

我遇到的问题是我的响应字符串来自服务器的长度令人难以置信。我想要做的就是从字符串中捕获“OK”消息。然后让我知道您已经对服务器进行了身份验证。我猜“isEqualToStirng”是错误的做法。所以我正在寻找替代方案。 :) 这是我的代码!谢谢!

这是来自服务器的字符串示例:2014-01-14 13:02:34.297 AppTest[84788:70b] 结果:{"result":"ok","userId":5,"appList":[{"appId":89,"appame":"塑料陌生人整容 ","userName":"Oblong","startDate":"2014-02-15T16:12:43","totView":1502,"totLike"‌ :2681,"totComment":3884}, {"appId":101,"appName":"安静的驴子 throw

NSURLResponse *response = nil;

NSData *dataURL = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];


NSString *responseString = [[NSString alloc]initWithData:dataURL encoding:NSUTF8StringEncoding];

NSLog(@"RESULT : %@", responseString);


if ([responseString isEqualToString:@"OK"])

{

UIStoryboard *mainStoryboard=[UIStoryboard

storyboardWithName:@"MainStoryboard" bundle:nil];

Home *mainView=[mainStoryboard

instantiateViewControllerWithIdentifier:@"mainView"];

mainView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;

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



}else{}

工作代码:

 NSError *e = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:&e];

NSString *result = json[@"result"];
if ([result isEqualToString:@"ok"])

{

UIStoryboard *mainStoryboard=[UIStoryboard

storyboardWithName:@"MainStoryboard" bundle:nil];

Home *mainView=[mainStoryboard

instantiateViewControllerWithIdentifier:@"mainView"];

mainView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;

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



}else

{}

最佳答案

您的响应表明您从服务器收到的是 JSON 字典。所以你会想做这样的事情:

NSError *e = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataURL options:0 error:&e];

NSString *result = json[@"result"];

关于ios - 验证登录表单,我正在使用 NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21120811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com