how to access all index set from JSON data using NSDictionary

I am trying to get my user name and password, which I am getting from my server. I already store in jsondata which is NSMutableArray. However I am getting only one data via -objectAtIndex:. I want to call my all data inside the dictionary. I know I have to use NSIndexSet but I don't know the proper way to use it. I'm using a for loop. I'm not able to access my value for key to match user credentials. Can anybody suggest anything? Here's my code:

    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];

    }        

Answers


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];

    }

You need to call a loop to access all the data on jsondata. Call as follows:

for (int i=0; i<[jsondata count]; i++)
{
 NSDictionary *dict = [jsondata objectAtIndex:i];
    if ([username.text isEqualToString:[NSString stringWithFormat: @"%@",[dict valueForKey:@"username"]]]&&[password.text isEqualToString:[NSString stringWithFormat: @"%@",[dict valueForKey:@"password"]]]) {
        username.text=nil;
        password.text=nil;

        [self performSegueWithIdentifier:@"login" sender:nil];

}

    else {
    UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Alert Title" message:@"Your alert messege" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [error show];

}
}

Need Your Help

How to limit the size of an azure blob container?

azure windows-azure-storage azure-storage-blobs

In my application, a web service send a shared access signature (write rights on container) to the client so it can upload files.

yeoman /app/bower_components missing

yeoman bower

I'm using generator angular to create my project. I've deleted my app/bower_components directory by accident. Is it possible to restore it?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.