1

我正在尝试在亚马逊上搜索电影标题,但 URL 有问题。电影名称以 '%@' 插入到链接中,但额外的 '%' 会导致问题。任何帮助,将不胜感激。

错误:

More '%' conversions than data arguments
Format specifies type 'int' but the argument has type 'NSString *'

这是我的代码:

- (void)jumpToAmazon:(id)sender {
    // create the string that points to the correct Amazon page for the game name
    NSString *amazonPageString = [NSString stringWithFormat:@"http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Dmovies-tv&field-keywords=%@&sprefix=friend%2Cmovies-tv&rh=i%3Amovies-tv%2Ck%3A%@", self.movie.name, self.movie.name];
    if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:amazonPageString]])
    {
        // there was an error trying to open the URL. for the moment we'll simply ignore it.
    }
}
4

3 回答 3

2

%%当您希望在字符串中显示实际的百分号时使用。

于 2013-10-05T19:39:11.397 回答
2

像这样加倍文字百分比:

[NSString stringWithFormat:
@"http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%%3Dmovies-tv&field-keywords=%@&sprefix=friend%%2Cmovies-tv&rh=i%%3Amovies-tv%%2Ck%%3A%@",
self.movie.name, self.movie.name];
于 2013-10-05T19:39:28.203 回答
1

在 URL 的位置,url=search-alias%3Dmovies-tv您需要添加另一个 % 符号以使其看起来像url=search-alias%%3Dmovies-tv. 也是如此friend%2Cmovies-tv&rh=i%3Amovies-tv%2Ck%3,您需要将其更改friend%%2Cmovies-tv&rh=i%%3Amovies-tv%%2Ck%%3为才能打印百分号。

于 2013-10-05T19:51:09.147 回答