用于布尔值的iPhone NSXML解析器
问题描述:
我正致力于通过从XML文件http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime中读取来确定事件是否为活动。用于布尔值的iPhone NSXML解析器
它返回一个布尔结果,但我不知道如何使用objective-c来访问它。这是我到目前为止有:
NSError * error = nil;
NSString * responseString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime"] encoding:NSUTF8StringEncoding error:&error];
NSLog(responseString);
if (error) {
NSLog(@"%@", [error localizedDescription]);
}
if ([responseString isEqualToString:@"true"]) {
// Handle active content.
NSString *baseVideoUrl = @"http://streaming5.calvaryccm.com:1935/live/iPhone/playlist.m3u8";
NSLog(@" finalUrl is : %@",baseVideoUrl);
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:baseVideoUrl]];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
// Use the 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
} else {
// Inform user that the content is unavailable
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Live Service"
message: @"There is no service going on at this time"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
答
首先你的NSLog的说法应该是:
NSLog(@"%@", responseString);
这将正常注销响应字符串,然后你会得到这个值回(我刚试了一下):因为它是完全合格的XML字符串表示
<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>
你的应答串不等于事实。您需要搜索字符串,您可以通过查找它是否包含文本“true”或“false”来执行此操作。
NSRange range = [responseString rangeOfString : @"true"];
if (range.location != NSNotFound) {
//String contained true
}
或者您可以使用像GDataXMLNode
+0
它工作!感谢您的帮助! –
你在responseString获得什么样的价值回一个轻量级的XML解决方案? – Anna
操作无法完成。 (可可错误256.) –