簡體   English   中英

iPhone NSXML解析器的布爾值

[英]iPhone NSXML Parser for a Boolean Value

我正在通過從XML文件http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime讀取來確定事件是否正在直播。

它返回一個布爾結果,但是我無法弄清楚如何使用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 version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>

您的響應字符串不等於true,因為它是完全限定的XML字符串表示形式。 您需要搜索字符串,可以通過查找字符串是否包含文本“ true”或“ false”來實現。

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

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

或者,您可以使用輕量級的XML解決方案,例如GDataXMLNode

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM