php - JSON -> Xcode 字符串格式

标签 php iphone mysql xcode json

我使用这种方法从 Xcode 访问我的 mysql 数据库:

NSString *URL = [NSString stringWithFormat:@"http://test.test:8888/test/loadUserData.php?username=%@", userName];

NSString *rawJSON = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:URL]];

const char *convert = [rawJSON UTF8String]; NSString *responseString = [NSString stringWithUTF8String:convert];

if ([rawJSON length] == 0) { [rawJSON release];

}

SBJsonParser *parser = [[SBJsonParser alloc] init];

userInfo = [[parser objectWithString:responseString error:nil] copy]; SSN = [userInfo objectAtIndex:0];

[parser release];

return userInfo;

一切正常。除了我无法将结果中的字符串与普通的 nsstrings 进行比较。如果我说

if ([userinfo objectAtIndex:0) == @"Dan") { ..做一点事

Xcode 永远看不到它是相同的值.. 不知道是不是格式有问题(我的数据库是UTF-8) 我如何转换结果以便 xCode 可以将响应与 NSStrings 进行比较?

谢谢!

最佳答案

== 不比较字符串的值,它只比较它们的地址。

使用

if ([[userinfo objectAtIndex:0] isEqualToString:@"Dan"]) { ... } 

或类似的东西。

关于php - JSON -> Xcode 字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6019893/

相关文章:

php - 变体产品两次显示价格| WordPress WooCommerce

php - 我可以使用 CI 进行多次事务更新,如果更新失败则将其全部回滚吗?

php - Intellij项目结构: Configure PHP SDK

ios - 从 AVPlayerViewController 中删除缓冲事件指示器

mysql - WordPress 和 Haversine 公式

php - 如何在 hostgator 托管服务器 cpanel 上的 cron 作业上运行 laravel 5.2 artisan 命令?

Iphone 遮蔽颜色 : Remove background color

iphone - 从 iPhone 中的 WAV 文件中去除背景噪音

mysql - 使用 information_schema 查找 innodb 数据库的大小

MYSQL导入空值