objective-c - 无效的转换说明符 '+'

标签 objective-c ios7 nsstring

我查过这个问题,但答案似乎总是针对该问题。

我正在尝试使用 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/

相关文章:

ios - 横向 UIWebView 自动调整大小(Swift)

ios - UISearchBar范围栏在iOS7中不可见

iphone NSString stringWithFormat 和 float

objective-c - Objective-C : Gesture Issue

objective-c - 如何确定两个NSD何时相隔1周?

iphone - 获取 DropBox 的文件夹结构并在特定文件夹中创建文件夹和上传文件 - iPhone

ios - 在 UILabel et.al 中使用 NSString 子类

ios - 如何在 iOS 7 上更改状态栏背景颜色和文本颜色?

ios - 如何在 IOS 7 中而不是在 IOS 6 中执行代码块?

ios - Objective-C 删除 ANSI 颜色控制代码