我正在制作一个通过 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
提前致谢,
莫里斯。