RestKit 0.20:如何在没有包装类的情况下 POST/GET 1 个以上的托管对象? [英] RestKit 0.20: How to POST/GET more than 1 managed object without a wrapper class?

查看:47
本文介绍了RestKit 0.20:如何在没有包装类的情况下 POST/GET 1 个以上的托管对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有几个实例需要向服务器发送一组对象:

Currently I have several instances where I need to send a group of objects to the server:

{
    "things": [
        {
            //object stuff
        },
        {
            //object stuff
        },
        ...
    ]
}

所以我一直在做的是定义一个中间对象 MyThingPayload

So what I've been doing is defining an intermediate object MyThingPayload

@interface MyThingPayload
@property (nonatomic, strong) NSArray *things;
@end

然后在映射时

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:NSClassFromString(@"MyThingPayload")];

[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"things"
                                                                        toKeyPath:@"things"
                                                                      withMapping:[self entityMappingForManagedThingObject]]];

似乎是不必要的开销.有没有办法在没有保存数组的中间对象的情况下做到这一点?

Seems like unnecessary overhead. Is there a way to do this without the intermediate object that holds an array?

推荐答案

您需要一个中间对象来提供序列化期间要使用的结构.不过,它不需要是一个自定义类,它可以是一个包含正确键和 NSArray 值的 NSDictionary.

You need an intermediate object to provide the structure to be used during serialisation. It doesn't need to be a custom class though, it can just be an NSDictionary containing the correct key and NSArray value.

这篇关于RestKit 0.20:如何在没有包装类的情况下 POST/GET 1 个以上的托管对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆