1

我想通过 JSON 执行登录,使用 PHP webservices,但问题是它一直给输出无效用户我能做什么?

lementation LoginViewController
NSString *username;
NSString *password;
@synthesize arr,json;

- (IBAction)btnLogin:(id)sender {
        username=txtUserName.text;
        password=txtPassword.text;
    NSString *post = [NSString stringWithFormat:@"user_name=%@&user_password=%@",username,password];
        NSLog(@"post data value is:%@",post);
        NSString *hostStr =@"http://myjsonwork.com/working_apps/?";
        hostStr = [hostStr stringByAppendingString:post];


        NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]];
        json=[NSJSONSerialization JSONObjectWithData:dataURL options:kNilOptions error:nil];

        NSString *str=[json objectForKey:@"success"];
        NSLog(@"post data value is:%@",hostStr);
        NSLog(@"post dataURL value is:%@",dataURL);


        if ([str isEqualToString:@"True"])
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Congrats" message:@"You are //authorised" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
        [alert show];

        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Invalid Username and password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
            [alert show];
                    }
        }
4

0 回答 0