Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS json标识_Ios_Json - Fatal编程技术网

iOS json标识

iOS json标识,ios,json,Ios,Json,我的代码有问题。我有一个与我的wep.api的post连接,它工作得很好。我得到我输入的信息。我试图对从web.api获得的json响应进行字符串化,并通过字符串对其进行比较,以查看用户是否进入下一页。问题是,即使我输入的信息是错误的,我仍然会被发送到下一页。这是我的密码 [5:39:03 PM] Marco Tejada: -(void) connectionDidFinishLoading:(NSURLConnection *) connection { NSLog(@"DONE.

我的代码有问题。我有一个与我的wep.api的post连接,它工作得很好。我得到我输入的信息。我试图对从web.api获得的json响应进行字符串化,并通过字符串对其进行比较,以查看用户是否进入下一页。问题是,即使我输入的信息是错误的,我仍然会被发送到下一页。这是我的密码

[5:39:03 PM] Marco Tejada: -(void) connectionDidFinishLoading:(NSURLConnection *) connection {
    NSLog(@"DONE. Received Bytes: %d", [webData length]);

    NSString *theJson = [[NSString alloc]
                        initWithBytes: [webData mutableBytes]
                        length:[webData length]
                        encoding:NSUTF8StringEncoding];



NSScanner *scanner1 = [NSScanner scannerWithString:theJson];
NSLog(@"%@", theJson);
if ([scanner1 scanUpToString:@"{\"ResultCode\": 0,\"ResultMessage\": \"Success log in\"}" intoString: NULL])
{

    [self performSegueWithIdentifier:@"sesepuede"sender:self];

}

else {
    NSLog(@"Username not found");{

    }
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Try Again" message:@"Credentials are incorrect" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [message show];
    }
}

@end

有人知道错误是什么吗?

您不应该将Json压缩到字符串中,而应该对nsdictionary进行水合处理,并使用键值对查找值

NSData *jsonData = [json dataUsingEncoding:NSASCIIStringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
NSLog(@"JSON: %@", jsonDict);

谢谢你,本!我现在明白了。