无法正确格式化字符串 URL 。 想要的输出是 :
http://gdata.youtube.com/feeds/api/videos?q=corgi&start-index=1&max-results=50&v=2&fields=entry%5Blink/@rel= http://gdata.youtube.com/schemas/2007%23mobile %5D
这是我最初的代码:
NSString *urlRequest = [NSString stringWithFormat:@"http://gdata.youtube.com/feeds/api/videos?q=corgi&start-index=%u&max-results=%u&v=2&fields=entry[link/@rel= http://gdata.youtube.com/schemas/2007%23mobile ]", dataStartIndex, dataIncrements];
NSURL *url = [NSURL URLWithString:urlRequest];
它不停地在结尾处堵住% 23 移动器, 并使之成为 20072obile 。 我尝试了在 @ 符号之前使用一个符号, 但没有成功 。 我做错了什么?
奇怪的是,如果我把它破碎成两块,它的工作就是正确的:
NSString *urlRequest = [NSString stringWithFormat:@"http://gdata.youtube.com/feeds/api/videos?q=corgi&start-index=%u&max-results=%u&v=2&fields=entry", dataStartIndex, dataIncrements];
NSURL *url = [NSURL URLWithString:[urlRequest stringByAppendingString:@"[link/@rel= http://gdata.youtube.com/schemas/2007%23mobile ]"]];
如果我这样做没有任何论据(dataStartIndex, dataIncrements),