我正在开发一个应用程序,我需要在 NSURL 中一次传递多个参数 我的代码是
responseData = [[NSMutableData data] retain];
ArrData = [NSMutableArray array];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=%@",strfrom,strto,strgo]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
//NSURLRequest *request1 = [NSURLRequest requestWithURL:
//[NSURL URLWithString:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=1",strfrom,strto]];
上面的代码我需要动态传递一个以上的参数。可能吗 ? 如果是,那又如何呢? 谢谢和问候
最佳答案
尝试在添加到 URL 之前创建一个单独的字符串
NSSString *strURL=[NSString stringWithFormat:@"http://rate-exchange.appspot.com/currency?from=%@&to=%@&q=%@",strfrom,strto,strgo];
然后将这个 strURL 添加到 URL
NSURL *url = [NSURL URLWithString:strURL];
最后将它添加到请求中,你的代码在你向请求中添加 url 的地方是错误的,URL 不是一个字符串它是一个 URL 所以它应该是 requestWithURL
而不是 URLWithString
,应该是这样的
NSURLRequest *request = [NSURLRequest requestWithURL:url];
关于iphone - 如何在 iOS 的 NSURL 字符串中传递多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15089000/