Satyam Raikar
Satyam Raikar

Reputation: 473

Reskit v0.2 Mapping for json format

{
"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"
                }
            ]
}

i have Job Class with jobid, userid and nsmutable_array "folderversion"

FolderVersions: is mapped using FolderVersion class having folder_id and version

i want FolderVersions mapped to folderversion array in job class

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)];

Upvotes: 0

Views: 57

Answers (1)

Wain
Wain

Reputation: 119021

You need to add a relationship mapping to your jobMapping, which links to the key in the Job class to the key in the JSON (FolderVersions) and specifies that it should use the folderMapping for the content:

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

Upvotes: 1

Related Questions