0
我有以下对象发布字符串JSON阵列RestKit
@interface MyObject : NSObject
@property(nonatomic, copy) NSNumber *objectId;
@property(nonatomic, copy) NSArray *tags; // array of strings, e.g. @[@"one", @"two"]
@end
我想后使用RestKit(0.23版本)的请求到URL
<base_url>/do_something/:objectId
请求正文应该只是一个根据tags
属性的字符串JSON数组,即
["one", "two"]
我有一个路由def独立非执行董事。现在
RKRoute *route = [RKRoute routeWithClass: [MyObject class] pathPattern: do_something/:objectId method: RKRequestMethodPOST];
[objectManager.router.routeSet addRoute: route];
,我想创建一个请求
[objectManager requestWithObject: instanceOfMyObject method: RKRequestMethodPOST path: nil parameters: nil];
我应该如何配置[RKObjectMapping requestMapping]
,我应该如何定义一个RKRequestDescriptor
获得上述(JSON字符串数组)的映射?
我曾尝试以下:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addPropertyMapping: [RKAttributeMapping attributeMappingFromKeyPath: @"tags" toKeyPath: nil]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping: requestMapping objectClass: [MyObject class] rootKeyPath: nil method: RKRequestMethodAny];
然而,在RKAttributeMapping
崩溃使用nil
作为关键路径。使用在要求任何未零值会导致它的身体是一个JSON字典
{"someKeyPath": ["one", "two"]}
您是否尝试过创建映射和描述符?显示您尝试的代码并解释它做错了什么。 – Wain 2015-02-06 17:45:09
@编辑过的问题。 – Cimlman 2015-02-12 08:21:14
在这种情况下使用NSJSONSerialization会更容易 – Wain 2015-02-12 09:54:59