如何比較網站結果和預測結果。xcode iOS比較字符串
@"document.getElementsByTagName('body')[0].outerHTML"
預測包含:
<body>OK</body>
但我總是得到一個錯誤,說他們不匹配。我用下面的代碼來比較它們:
if (webresult == cmp){
然後它顯示一個警告說成功。否則,它會說錯誤。它總是去其他地方。繼承人的代碼塊,請幫助。
- (IBAction)displayresult:(id)sender {
webresult = [webview2 stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].outerHTML"];
NSString *cmp = [[NSString alloc] initWithFormat:@"<body>OK</body>"];
if (webresult == cmp) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logged in" message:@"Logged in, Proceeding to the game" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:webresult delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}
謝謝,修好了吧 –
太好了!你能接受答案嗎? – msgambel