所以我试图从来自 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"]];
有任何想法吗?提前致谢!