【发布时间】:2010-08-04 18:24:07
【问题描述】:
所以我试图从来自 URL 的 XML 流中检索数据。此 URL 是在用户输入的搜索字符串上配置的。这段代码不应该工作有什么原因吗?
NSString *searchString = "Geoff";
NSString *updatedURL = [NSString stringWithFormat:@"http://mysearchpage.com/searchQuery=%@", searchString];
NSLog(updatedURL);
NSURL *url = [[NSURL alloc] initWithString:updatedURL];
现在这适用于单个单词搜索,但是一旦我尝试搜索名字和姓氏,URL 每次都返回 nil。字符串是否有任何可能导致这种情况的行为?
我什至尝试在附加搜索字符串时将“”替换为“%20”,以查看是否是问题所在。我是这样做的:
NSURL *url = [[NSURL alloc] initWithString:[updatedURL stringByReplacingOccurrencesOfString:@" " withString:@"%%20"]];
有什么想法吗?提前致谢!
【问题讨论】:
-
我假设丢失的 " 不是你的问题,所以我添加了它。
标签: objective-c nsstring nsurl