2016-10-18 6 views
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); 
    } 
    } 
+2

で確認してください認識されていないselector'は単に意味し、受信機は、配列ではなく、辞書です。 – vadian

+0

@Dipekキー "状態"はあなたの応答に存在しません。 –

答えて

0

[__NSArrayM objectForKey:]:これを試してみて、国家重点が `第一存在か

- (void) logIn { 

    ///1 
NSMutableDictionary *responseDic_Lv=[[NSMutableDictionary alloc]init]; 
NSString *post_Lv = [NSString  stringWithFormat:@"email_id=%@&password=%@"  ,userNameTFT1.text,passwordTFT2.text]; 


///2 
NSData *postData_Lv = [post_Lv dataUsingEncoding:NSASCIIStringEncoding  allowLossyConversion:YES]; 
NSString *postLength_Lv = [NSString stringWithFormat:@"%lu",(unsigned  long)[postData_Lv length]]; 

//NSLog(@"Post Length Is... %@",postLength_Lv); 


//3 
NSString *BaseUrl_Login = [NSString stringWithFormat:@"Your_Login_URL"]; 

    NSMutableURLRequest *request_Lv =[[NSMutableURLRequest alloc] init]; 
[request_Lv setURL:[NSURL URLWithString:BaseUrl_Login]]; 

//NSLog(@" Rahul Goku request is >>> %@",request); 

    [request_Lv setHTTPMethod:@"POST"]; //Write Post or Get accordind method here 

    [request_Lv setValue:postLength_Lv forHTTPHeaderField:@"Content-Length"]; 

    [request_Lv setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

    [request_Lv setHTTPBody:postData_Lv]; //Set HTTP 

    NSData *response_Lv = [NSURLConnection sendSynchronousRequest:request_Lv 
    returningResponse:nil error:nil]; 

    responseDic_Lv=[NSJSONSerialization JSONObjectWithData:response_Lv options:NSJSONReadingAllowFragments error:nil]; 



///4 Chk Data... 
    NSString *ResultStr1 = (NSString *)[responseDic_Lv valueForKey:@"YourKey"]; 

NSLog(@"Result From Server is=====> %@",ResultStr1); 


if ([ResultStr1 isEqualToString:@"success"]) { 


NSString *ResponseStr2 = (NSString *)[responseDic_Lv valueForKey:@"YourKey"]; 



} else { // Login Error password or email.... Error... 


    } 



} 
関連する問題