サーバーから取得しているユーザー名とパスワードを取得しようとしています。私はすでにどこに保存してjsondata
いますNSMutableArray
。ただし、を介して取得して-objectAtIndex:
いるデータは1つだけです。辞書内のすべてのデータを呼び出したい。使用する必要NSIndexSet
があることはわかっていますが、適切な使用方法がわかりません。for
ループを使用しています。ユーザーの資格情報と一致するキーの値にアクセスできません。誰かが何かを提案できますか?これが私のコードです:
NSDictionary *dict = [jsondata objectAtIndex:0];
if ([username.text isEqualToString:[dict valueForKey:@"username"]]&&[password.text isEqualToString:[dict valueForKey:@"password"]]) {
username.text=nil;
password.text=nil;
[self performSegueWithIdentifier:@"login" sender:nil];
}
else {
UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Oooops" message:@"Login Credentials did`t Match" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[error show];
}
NSString *tusername = nil;
NSString *tpassword = nil;
BOOL isLogin = NO;
//jsondata contains many dictionary, so iterate the loop and find the dictionary that
//contains username and password
for(id temp in jsondata)
{
//check whether the object is Dictionary or not
if([temp isKindOfClass:[NSDictionary class]])
{
NSDictionary *dict = temp;
if([[dict allKeys] containsObject:@"username"])
{
tusername = [dict valueForKey:@"username"];
}
else if([[dict allKeys] containsObject:@"password"])
{
tpassword = [dict valueForKey:@"password"];
}
//Check the condition here
if(tusername != nil && tpassword != nil)
{
if ([username.text isEqualToString:tusername] && [password.text isEqualToString:tpassword])
{
isLogin = YES;
username.text=nil;
password.text=nil;
[self performSegueWithIdentifier:@"login" sender:nil];
break;
}
}
}
}
if(!isLogin)
{
UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Oooops" message:@"Login Credentials did`t Match" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[error show];
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加