0

我在让它正常运行时遇到问题。

我已经映射了我想要注入到请求中的 JSON 有效负载的键值对,但我最终在每个帖子上都失败了。

以下几行向我展示了创建请求:

RKObjectMapping *requestMapping = [WDMappingProvider createRegInitRequestTicketMapping];
    RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[requestMapping inverseMapping] objectClass:[WDTicketsModel class] rootKeyPath:nil];
[registrationManager addRequestDescriptor:requestDescriptor];

然后我创建我的发布路径并将数据放入我的发布请求:

//Make object from params
    WDRegistrationInitializeRequestModel *requestModel  = [[WDRegistrationInitializeRequestModel alloc] init];

    requestModel.eventID = [params objectForKey:@"eventID"];
    requestModel.arrayOfTicketDictionaries  = [params objectForKey:@"arrayOfTicketDictionaries"];

    NSString *postPath = [NSString stringWithFormat:@"api/v1/registrations/initialize?eventid=%@", requestModel.eventID];

    //Post the object (aka the interest json payload)
    [registrationManager postObject:requestModel.arrayOfTicketDictionaries path:postPath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result){ ...

在这一点上,我总是在 postObject 方法的失败块中结束。

我的 [WDMappingProvider createRegInitRequestTicketMapping] 映射如下所示:

+(RKObjectMapping *)createRegInitRequestTicketMapping
{
    RKObjectMapping *regInitRequestMapping = [RKObjectMapping mappingForClass:[WDTicketsModel class]];
    [regInitRequestMapping addAttributeMappingsFromDictionary:
     @{
        @"Quantity" : @"quantity",
        @"TicketID":@"mainID"
     }];


    return regInitRequestMapping;
}

arrayOfTicketDictionaries 看起来像这样:

[{"Quantity":1,"TicketID":1604},{"Quantity":1,"TicketID":1605},{"Quantity":1,"TicketID":1606}]

有什么想法吗?

4

1 回答 1

0

我认为这是因为你错过了这个RKResponseDescriptor部分。尝试添加这个:

// Anything in 2xx
NSIndexSet *statusCodes =
  RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor =
  [RKResponseDescriptor
   responseDescriptorWithMapping:requestMapping
   method:RKRequestMethodAny
   pathPattern:nil
   keyPath:nil
   statusCodes:statusCodes];
[registrationManager addResponseDescriptor: responseDescriptor];
于 2013-08-20T03:00:23.417 回答