用于发布 JSON 列表的 RestKit 映射

RestKit Mapping for POSTing JSON List

是否可以使用 RestKit POST 向需要 JSON 词典列表的服务器发出请求? :

[
  { "key1":"value1",
    "key2":"value2"
  }
]

Wiki:https://github.com/RestKit/RestKit/wiki/Object-Mapping#mapping-without-kvc describes how this can be done on a response - mapping from JSON to objects - but not the other way around - objects to JSON. To complicate the problem I think, the URL request is of the form http://www.example.com/some-name/upload - 不是很 restful。

感谢您的帮助。

编辑:

感谢 Wain 迫使我更深入地寻找解决方案 - 我不确定是否可行。基于 blakewatters 记录的 RestKit 问题 398,我解决了这样的问题:

RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromDictionary:@{@"key1":@"value1", @"key2":@"value2"}];


RKRequestDescriptor *requestDescriptor =
[RKRequestDescriptor requestDescriptorWithMapping:requestMapping
                                      objectClass:[MyObjectClass class]
                                      rootKeyPath:nil
                                           method:RKRequestMethodPOST];

[objectManager addRequestDescriptor:requestDescriptor];


[[RKObjectManager sharedManager] postObject:@[self.myObject]
                                       path:@"/path/myobject/upload"
                                 parameters:nil
                                    success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                        NSLog(@"Success!");
                                    }
                                    failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                        NSLog(@"Fail.");
                                    }];

我认为关键是将 myObject 放在一个数组中,然后将 "rootKeyPath" 和 "parameters" 设置为 nil。

当然可以,它基本上是同一件事(映射)然后使用 inverseMapping 和请求描述符而不是响应描述符。

无论如何你都需要一个响应描述符,因为你需要处理响应...