Html 我无法创建在使用stringByappendingString时有效的NSURL

Html 我无法创建在使用stringByappendingString时有效的NSURL,html,ios,Html,Ios,以下URL在Safari中正常工作: NSURL *conversionUrl = [NSURL URLWithString:@"http://www.xe.com/currencyconverter/convert/?Amount=100&From=ALL&To=USD]; 以下操作不起作用,但NSLog返回相同的结果 如有任何意见,将不胜感激 NSString *newStringURL = [[[[[ @"http://www.xe.com/currencycon

以下URL在Safari中正常工作:

NSURL *conversionUrl = [NSURL URLWithString:@"http://www.xe.com/currencyconverter/convert/?Amount=100&From=ALL&To=USD];
以下操作不起作用,但NSLog返回相同的结果

如有任何意见,将不胜感激

NSString *newStringURL =
   [[[[[  @"http://www.xe.com/currencyconverter/convert/?Amount="  stringByAppendingString:@"100"]stringByAppendingString:@"&from="]stringByAppendingString:@"ALL"]stri ngByAppendingString:@"&to="]stringByAppendingString:@"USD"];
NSURL *conversionUrl = [NSURL URLWithString:newStringURL];  
NSLog(@"URL= %@",conversionUrl);
URL= http://www.xe.com/currencyconverter/convert/?Amount=100&from=ALL&to=USD
为什么不使用NSString*newStringURL=[NSString stringWithFormat:@http://www.xe.com/currencyconverter/convert/?Amount=%@&From=%@&To=%@、@100、@ALL、@USD]

只需将@100等值替换为所需值即可

看起来比用字符串附加字符串要干净得多

对于其他寻找正确答案的人来说,这是因为URL区分大小写


帮助stackoverflow用户在“答案”部分而不是在注释中查看答案。考虑接受这个答案。 我不知道这是否有什么区别,但是from和to在你的第二个字符串中是小写的,在第一个字符串中是大写的