【问题标题】:Mashape API objective-C boilerplate code giving errorsMashape API Objective-C 样板代码给出错误
【发布时间】:2013-07-13 04:22:33
【问题描述】:

我正在尝试使用来自 Mashape 的 API。 当我测试端点(JSON 响应)时,一切正常, 但是他们提供的objective-c app-ready代码示例不起作用,我收到以下错误:

这是我的代码:

- (IBAction)loadJson:(id)sender
{
    NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"xxxxxxxxx", @"X-Mashape-Authorization", nil];
    NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:[NSURL URLWithString:@"<file url>"], @"files", @"", @"urls", nil];

    HttpJsonResponse* response = [[Unirest post:^(BodyRequest* request) {
        [request setUrl:@"https://lambda-face-recognition.p.mashape.com/detect"];
        [request setHeaders:headers];
        [request setParameters:parameters];
    }] asJson];
}

有没有办法解决这个问题?

谢谢!

【问题讨论】:

    标签: xcode json mashape


    【解决方案1】:

    code examples 显示代码实际上应该是这样的:

    NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil];
    NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", @"bar", @"foo", nil];
    
    HttpJsonResponse* response = [[Unirest postEntity:^(BodyRequest* request) {
      [request setUrl:@"http://httpbin.org/post"];
      [request setHeaders:headers];
      // Converting NSDictionary to JSON:
      [request setBody:[NSJSONSerialization dataWithJSONObject:headers options:0 error:nil]];
    }] asJson];
    

    或者,也许是这个:

    NSDictionary* headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/json", @"accept", nil];
    NSURL file = nil;
    NSDictionary* parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"parameter", file, @"file", nil];
    
    HttpJsonResponse* response = [[Unirest post:^(MultipartRequest* request) {
      [request setUrl:@"http://httpbin.org/post"];
      [request setHeaders:headers];
      [request setParameters:parameters];
    }] asJson];
    

    【讨论】:

      猜你喜欢
      • 2014-05-01
      • 2018-11-16
      • 1970-01-01
      • 2012-12-15
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      相关资源
      最近更新 更多