如果Statement使用PHP Echo和isEqualToString

时间:2013-07-01 23:40:31

标签: ios objective-c

我绝对会疯狂地想弄清楚下面我做错了什么。我有一个PHP文件,它根据一些计算回显0或1。如果结果为0,我想显示一个警报。如果结果为1,我想显示不同的警报。

奇怪的是,当我在警报中包含从PHP文件返回的字符串(下面名为aroundURLString)时,它会正确显示。 (我的意思是警报的'message'字段正在工作,并证明PHP文件正在返回正确的值....)

但是,我的问题是if语句没有按照我的预期运行。有谁知道我在做错了什么?我疯了想试试这个。谢谢!

    NSData *aroundURLResult = [NSData dataWithContentsOfURL:[NSURL 
    URLWithString:aroundURL]];

    // to receive the returend value
    NSString *aroundURLString = [[NSString alloc] initWithData:aroundURLResult 
    encoding:NSUTF8StringEncoding];

    if ([aroundURLString isEqualToString:@"0"]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"the string is 0" 
        message:aroundURLString delegate:self cancelButtonTitle:@"OK" 
        otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

    if ([aroundURLString isEqualToString:@"1"]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"the string is 1" 
        message:aroundURLString delegate:self cancelButtonTitle:@"OK" 
        otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

0 个答案:

没有答案