我查过这个问题,但答案似乎总是针对该问题。
我正在尝试使用 JSON 从 Web 服务器请求信息,并将信息显示在表格 View 中。给我带来麻烦的代码如下:
CalendarCommunicator.m
:
#import "CalendarCommunicator.h"
#import "CalendarCommDelegate.h"
@implementation CalendarCommunicator
- (void)searchGroupsAtCoordinate:(CLLocationCoordinate2D)coordinate
{
NSString *urlAsString = [NSString stringWithFormat:@"http://medpak.costarica.com/api/content/render/false/type/json/query/+structureName:calendarEvent%20+(conhost:9fe93d82-1cd8-46b1-9dda-8b940e407d23%20fonhost:SYSTEM_HOST)%20+languageId:1", coordinate.latitude, coordinate.longitude];
NSURL *url = [[NSURL alloc] initWithString:urlAsString];
NSLog(@"%@", urlAsString);
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:url] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
[self.delegate fetchingGroupsFailedwithError:error];
} else {
[self.delegate recievedGroupsJSON:data];
}
}];
}
@end
在 NSString *urlAsString
部分中,我收到有关 URL 的警告。它说'“无效的转换说明符'+'”。这到底是什么意思? URL 中是否有很多“+”号,还是我遗漏了什么?
最佳答案
原因是 %
对 URL 的百分比编码和格式化字符串都有意义。在这种情况下,+stringWithFormat
在您的字符串中看到了 %20+
,并认为您正在给它一个格式化命令。对于您的 URL 格式字符串中的文字 %
,将它们设为 %%
,即将 %%
传递给字符串格式化方法/函数以获取文字 %
.
但是,在您的特定情况下,我不确定您要用哪些位置代替位置以及您打算将哪些位置作为百分比转义。
关于objective-c - 无效的转换说明符 '+',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23305692/