0

API を介してデータベースと通信する iOS アプリケーションを作成しています。API は有効な JSON をアプリケーションに送信しますが、アプリケーションはエラーを返さず、別の結果 NULL を返します。

iOS アプリのコードは次のとおりです。

 // Start hud
 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
 hud.labelText = @"Zoeken...";

 return TRUE;
 }

    - (void)requestFinished:(ASIHTTPRequest *)request
   {    
 [MBProgressHUD hideHUDForView:self.view animated:YES];
if (request.responseStatusCode == 400) {
    textView.text = @"Invalid code";        
} else if (request.responseStatusCode == 403) {
    textView.text = @"Code already used";
} else if (request.responseStatusCode == 204) {
    textView.text = @"No content";
} else if (request.responseStatusCode == 412) {
    textView.text = @"Precondition Failed";
} else if (request.responseStatusCode == 200) {
    NSString *responseString = [request responseString];
    NSDictionary *responseDict = [responseString JSONValue];
    // NSString *naam = [responseDict objectForKey:@"DEB_NR"];

    NSString *part0 = [responseDict objectForKey:@"klntnr"];
    NSString *part1 = [responseDict objectForKey:@"klntnm"];
    NSString *part2 = [responseDict objectForKey:@"adrs"];
    NSString *show = [NSString stringWithFormat:@"\r%@\r%@\r%@" , part0 , part1 , part2 ];

   // if ([unlockCode compare:@"com.razeware.test.unlock.cake"] == NSOrderedSame) {
        textView.text = [NSString stringWithFormat:@"Resultaten: %@", show];
  //  } else {
       // textView.text = [NSString stringWithFormat:@"Resultaat: %@", unlockCode];
  //  }

  } else {
      textView.text = @"Unexpected error API ERROR";
  }

}

 - (void)requestFailed:(ASIHTTPRequest *)request
 {    
 [MBProgressHUD hideHUDForView:self.view animated:YES];
 NSError *error = [request error];
  textView.text = error.localizedDescription;
  }

 @end

前もって感謝します、

モーリス。

4

1 に答える 1

-1

JSON 文字列を表示するだけで本当に役に立ちます。しかし、これを試してください

else if (request.responseStatusCode == 200) {

NSError* error;
NSString *responseString = [request responseString];
NSArray *responseObj = [NSJSONSerialization JSONObjectWithData: [responseString dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &error];
NSString *part0=@"";
NSString *part1=@"";
NSString *part2=@"";

for (int i=0; i<[responseObj count]; i++) {
    NSDictionary *dataDict = [responseObj objectAtIndex:i];
    NSString *part0 = [dataDict objectForKey:@"klntnr"];
    NSString *part1 = [dataDict objectForKey:@"klntnm"];
    NSString *part2 = [dataDict objectForKey:@"adrs"];
}
NSString *show = [NSString stringWithFormat:@"\r%@\r%@\r%@" , part0 , part1 , part2 ];
textView.text = [NSString stringWithFormat:@"Resultaten: %@", show];
}
于 2013-05-21T14:24:31.240 に答える