【发布时间】:2012-05-24 04:37:37
【问题描述】:
我无法正确获取字符串 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),它也可以工作。
【问题讨论】: