简体   繁体   English

iPhone NSXML解析器的布尔值

[英]iPhone NSXML Parser for a Boolean Value

I am working on determining if an event is live by reading from an XML file http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime . 我正在通过从XML文件http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime读取来确定事件是否正在直播。

It returns a boolean result, but I cannot figure out how to access it using objective-c. 它返回一个布尔结果,但是我无法弄清楚如何使用Objective-C访问它。 This is what I have so far: 这是我到目前为止的内容:

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];
}

Firstly your NSLog statement should be: 首先,您的NSLog语句应为:

NSLog(@"%@", responseString); 

This will properly log out the response String, you will then get this value back (I just tried it): 这将正确注销响应字符串,然后您将获得该值(我刚刚尝试过):

<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>

Your response String is not equal to true because it is the fully qualified XML String representation. 您的响应字符串不等于true,因为它是完全限定的XML字符串表示形式。 You need to either search the String, you could do this by looking for if it contains the text "true" or "false". 您需要搜索字符串,可以通过查找字符串是否包含文本“ true”或“ false”来实现。

NSRange range = [responseString rangeOfString : @"true"];

if (range.location != NSNotFound) {
    //String contained true
}

Alternatively you can use a lightweight XML solution like GDataXMLNode 或者,您可以使用轻量级的XML解决方案,例如GDataXMLNode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM