【发布时间】:2013-05-24 15:12:10
【问题描述】:
我在 Restkit 0.20 中遇到了请求映射问题。我想将一个带有 NSStrings 的 NSArray 放入请求中的“邮件”键下,例如:
{mails:[@"first@gmail.com",@"second@gmail.com"]}
因此,对于这种情况,我真的不需要对象映射,因为我只使用标准对象。我只是没有让它工作,所以我切换回常规方式(至少对我来说) - 引入一个包含 NSArray 的 DTO 对象 MailRequest。我是这样做的:
RKObjectMapping* mapping = [RKObjectMapping requestMapping];
[mapping addAttributeMappingsFromDictionary:@{
@"mails":@"mails"
}];
RKRequestDescriptor *reqDesc =
[RKRequestDescriptor requestDescriptorWithMapping:mapping
objectClass:[MailRequest class]
rootKeyPath:nil];
RKObjectManager *manager = ...
...
NSMutableURLRequest *request = [manager requestWithObject:requestObject
method:RKRequestMethodPOST
path:urlString parameters:nil];
RKObjectRequestOperation *operation =
[manager objectRequestOperationWithRequest:request ...
...但我想摆脱 MailsRequest DTO 对象。这可能吗?
【问题讨论】:
-
如果您的对象与其他对象具有数组关系,该对象应具有字符串作为属性。显示存储字符串的数据结构。
-
嗨,我不想像在我的示例中那样使用对象(如 MailsRequest)。相反,我想将数组直接放入请求中。
-
那么为什么不自己创建 JSON 和 NSURLRequest(使用 JSON 数据),然后传递给 RKObjectRequestOperation 呢?
-
听起来不错,有小例子吗?
标签: ios objective-c ios6 restkit restkit-0.20