Ios Restkit 0.20对象嵌套数组映射问题

Ios Restkit 0.20对象嵌套数组映射问题,ios,objective-c,rest,restkit,Ios,Objective C,Rest,Restkit,我在使用RESTKit0.20映射以下JSON负载时遇到问题 我正在尝试将产品及其附件映射为具有以下对象的数组。我没有使用RKEntityMapping,只是RKEObjectMappings,因为这个应用程序没有使用核心数据。我在restkitwiki上查阅了关于对象映射的文档,并查看了源代码中的测试用例,以获得类似的设置,但运气不佳 { "Result": { "Product": { "Name": "Evil Stuff",

我在使用RESTKit0.20映射以下JSON负载时遇到问题

我正在尝试将产品及其附件映射为具有以下对象的数组。我没有使用RKEntityMapping,只是RKEObjectMappings,因为这个应用程序没有使用核心数据。我在restkitwiki上查阅了关于对象映射的文档,并查看了源代码中的测试用例,以获得类似的设置,但运气不佳

{
    "Result": {
        "Product": {
            "Name": "Evil Stuff",
            "Description": "Its EVIL!",
            "Attachments": [
                {
                    "Id": "c4277b8f-5930-4fee-a166-b5f311d3a353",
                    "Name": "commands_to_recreate_db.txt",
                    "Type": "Contraindications"
                },
                {
                    "Id": "be4d2e2e-cb3e-48d2-9c7a-fbfddea3a1be",
                    "Name": "json.txt",
                    "Type": "Medication Guide"
                }
            ]
        },
        "Company": {
            "Name": "Omni Consumer Products",
            "AddressLine1": "100 Evil Dr.",
            "AddressLine2": null,
            "AddressLine3": null,
            "City": "MARS",
            "State": null,
            "Zip": "10000",
            "Country": null,
            "PhoneNumber1": "555-555-5555",
            "PhoneNumber2": null,
            "PhoneNumber3": null,
            "FaxNumber": null,
            "WebSite": null,
            "Email": null
        },
        "Representatives": []
    },
    "Messages": [],
    "Success": true
}



@interface clinProduct : NSObject

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSArray *attachments;


@interface clinAttachment : NSObject

@property (strong, nonatomic) NSString *attachmentID;
@property (strong, nonatomic) NSString *attachmentName;
@property (strong, nonatomic) NSString *type;
以下是我的对象映射和RKResponseDescriptor

  RKObjectMapping *attachmentMapping = [RKObjectMapping mappingForClass:[clinAttachment class]];
  [attachmentMapping addAttributeMappingsFromDictionary:@{@"Id"   : @"attachmentID",
                                                         @"Name" : @"attachmentName",
                                                         @"Type" : @"type"}];
  RKObjectMapping *productMapping = [RKObjectMapping mappingForClass:[clinProduct class]];
  [productMapping addAttributeMappingsFromDictionary:@{@"Description" : @"description",
                                                              @"Name" : @"name"}];
  RKRelationshipMapping *relationshipMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Attachments"
                                                                                           toKeyPath:@"attachments"
                                                                                         withMapping:attachmentMapping];
  [productMapping addPropertyMapping:relationshipMapping];
  RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:productMapping
                                                                pathPattern:nil
                                                                    keyPath:@"Result.Product"
                                                                statusCodes:[NSIndexSet indexSetWithIndex:200]];
我得到了一个有效的响应,但奇怪的是它只映射了产品的description属性,甚至没有映射其名称

2013-03-05 18:39:49.775 iOS[38965:c07] Loaded results: <RKMappingResult: 0x96a8950, results={
    "Result.Product" = "Its EVIL!";

2013-03-05 18:39:49.775 iOS[38965:c07]加载的结果:为了方便用户查看答案:

@Jorge Chao对自己问题的评论(回答):

此问题的答案:


我已经解决了这个问题。首先,我粘贴的
RKMappingResult
不正确。它正在映射一个项,但只显示其一个属性。为了使其正常工作,我删除了product类中的
RKRelationshipMapping
NSAray
,并为附件添加了第二个
RKResponseDescriptor


所有内容都正确显示在
RKMappingResult
中,不幸的是,该数组只包含异构元素。这是一个黑客程序,但它最终解决了我的问题。

我已经解决了这个问题。首先,我粘贴的RKMappingResult不正确。它正在映射一个项,但只显示其一个属性。为了使其正常工作,我删除了product类中的RKRelationshipMapping和NSAray,并为附件添加了第二个RKResponseDescriptor。RKMappingResult中的所有内容都正确显示,但不幸的是,该数组只包含异构元素。这是一个黑客,但它最终解决了我的问题。你能把它作为一个答案吗?然后把它标记为答案?