0

我想按照下面的调用从 mysql 调用中获取一个整数,然后比较该值是 0 还是 1,我似乎对 NSSTRING 和 NURL 有问题...请帮助

当我将 mysql 设置为 value = 1 时,我仍然没有得到 NSLOG 的输出

 NSURL *database_flag_query;
 NSString *database_flag;



database_flag_query = [NSURL URLWithString: [NSString stringWithFormat: @"http://192.168.0.20/iqkradio_stream_ip.php"]];
database_flag = [NSString stringWithContentsOfURL:database_flag_query encoding:NSASCIIStringEncoding error:&error];


if([database_flag isEqualToString: @"1"])
{NSLog(@"flag = 1");}

新代码

database_flag_query = [NSURL URLWithString:@"http://192.168.0.20/iqkradio_stream_ip.php"];
database_flag = [NSString stringWithContentsOfURL:database_flag_query encoding:NSASCIIStringEncoding error:&error];
NSLog(database_flag);
if([database_flag isEqualToString: @"1"])
{NSLog(@"flag is set");}

这也是我的mysql查询

mysql_select_db("qkradio", $con);
$result = mysql_query("select flag from iqkradio" );
while($row = mysql_fetch_array($result)) {
echo $row['flag'];
4

1 回答 1

0

根据评论,您在输出末尾添加了一些额外的空格/换行符。

您可以按如下方式对其进行修剪:

database_flag = [NSString stringWithContentsOfURL:database_flag_query encoding:NSASCIIStringEncoding error:&error];
if (database_flag) {
    database_flag = [database_flag stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSLog(@"database_flag = '%@'", database_flag);
    if ([database_flag isEqualToString: @"1"]) {
        NSLog(@"flag is set");
    }
} else {
    NSLog(@"Error: %@", error);
}
于 2013-04-13T04:02:15.133 回答