当通过 PUT 方法放置数据时,我被困在如何构建我的对象和映射以实现这样的事情的问题上:“lastChanges/confirm”
上面的 PUT-Request 接受这样的主体来确认盒子 id 的同步:
{ "synchronized_boxes": [47292,someOtherBoxId,..] }
我尝试过构建这样的对象:
@interface RPConfirmSync : NSObject
@property (nonatomic, retain) NSArray *synchronized_boxes;
@end
在我发送这个对象之前,我将一些 NSNumber 对象添加到数组中。
我设置的映射如下所示:
RKObjectMapping *confirmMapping = [RKObjectMapping mappingForClass:[RPConfirmSync class]];
[confirmMapping addAttributeMappingsFromArray:@[@"synchronized_boxes"]];
RKObjectMapping *requestMapping = [confirmMapping inverseMapping];
NSString *pathPattern = [NSString stringWithFormat:@"lastsync/confirm"];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[RPConfirmSync class] rootKeyPath:nil];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:confirmMapping pathPattern:pathPattern keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.objectManager addRequestDescriptor:requestDescriptor];
[self.objectManager addResponseDescriptor:responseDescriptor];
现在,当我执行上面的 PUT-Request 并查看请求正文时,RestKit 调试信息向我显示了一些奇怪的东西,如下所示:
request.body=synchronized_boxes[]=47292 //being sent to the server !ERROR!
应该是
request.body=synchronized_boxes[47292]
我该如何设置我的对象或映射有问题?我真的被困在这里,尽管我想答案是直截了当的。