我无法正确获取字符串 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];
它最后一直在乱码“%23mobile”并使其成为“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),它也可以工作。