Reskit v0.2 json格式的映射

时间:2013-07-27 12:07:47

标签: iphone ios restkit restkit-0.20

{
"JobID" : "aaaabbbb-dddd-eeee-ffff-aaaabbbbcccc",
"UserID": "11112222-dddd-eeee-ffff-111122223333",

"FolderVersions" :  [
                {
                    "FolderID" : "11112222-dddd-eeee-ffff-111122223333",
                    "Version" : "1.0"
                },
                {
                    "FolderID" : "11113333-dddd-eeee-ffff-111122223333",
                    "Version" : "1.2"
                },
                {
                    "FolderID" : "33332222-dddd-eeee-ffff-111122223333",
                    "Version" : "1.1"
                }
            ]
}

我有jobid,jobid,用户ID和nsmutable_array“folderversion”

FolderVersions:使用具有folder_id和version

的FolderVersion类进行映射

我希望FolderVersions映射到作业类

中的folderversion数组
RKObjectMapping *jobMapping = [RKObjectMapping mappingForClass:[Job class]];
[jobMapping addAttributeMappingsFromDictionary:@{
 @"JobID" : @"jobId",@"USerID":@"userID"
      }];



    RKObjectMapping *folderMapping = [RKObjectMapping mappingForClass:[FolderVersion class]];
    [folderMapping addAttributeMappingsFromDictionary:@{@"FolderID":@"folderID",

 @"Version":@"version",

 }];



    RKResponseDescriptor *responseDescripor1 = [RKResponseDescriptor jobMapping
         method:RKRequestMethodPOST pathPattern:@"/xxx/response.php/json/response" 

keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

1 个答案:

答案 0 :(得分:1)

您需要添加一个关系映射到您的jobMapping,它将Job类中的键链接到JSON中的键(FolderVersions),并指定它应该使用内容的folderMapping

[jobMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"FolderVersions" toKeyPath:@"folderversion" withMapping:folderMapping]];