0
Jsonによってphpファイルのデータを取得するログインページを作成しようとしています。この文[jsonData objectForKey:@ "state"]を使用するまでは正常に動作しますが、例外が表示されます。私は前に質問するいくつかの答えのような別の双子座を作ろうとしました。私とは何の関係もありません。[__NSArrayM objectForKey:]:インスタンスに送信された認識できないセレクタ0x7faf59e2fd10
- (IBAction)login:(id)sender {
@try {
NSString *post =[[NSString alloc] initWithFormat:@"email=%@&password=%@",[firsttext text],[second text]];
NSLog(@"PostData: %@",post);
NSURL *url=[NSURL URLWithString:@"http://itsolution.co.in/coverageapi/login.php"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *error = nil;
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Response code: %d", [response statusCode]);
if ([response statusCode] >=200 && [response statusCode] <300)
{
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"Response ==> %@", responseData);
SBJsonParser *jsonParser = [SBJsonParser new];
NSDictionary *jsonData = (NSDictionary *) [jsonParser objectWithString:responseData error:nil];
NSLog(@"jsondata %@",jsonData);
NSInteger success = [(NSNumber *) [jsonData objectForKey:@"success"] integerValue];
NSLog(@"%d",success);
if(success == 1)
{
NSLog(@"Login SUCCESS");
} else {
NSLog(@"failed");
}
} else {
if (error) NSLog(@"Error: %@", error);
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
}
で確認してください認識されていないselector'は単に意味し、受信機は、配列ではなく、辞書です。 – vadian
@Dipekキー "状態"はあなたの応答に存在しません。 –