json - ios Restkit - Mapping objects with a list within another list -
i'm trying map objects using restkit. have no problems mapping normal json responses. in case have problem because want map response configuration:
{ "id": 161, "text": "usertest", "test": { "id": "1", "begindate": "17/04/2013", "expectedduration": "45 minutes", "finishdate": "17/04/2013", "groups": [ { "id": 71, "text": "some text", "number":"number" }, { "id": 81, "text": "some anothertext } ] ... }
as can see, have main object 3 attributes(id, text , list of tests). each test has attributes(id, begindate,...,). each test has list of groups. , here problem. when try map this, restkit can't map 'groups' list.
i'm mapping this code:
//### test rkentitymapping *testcompletemapping = [rkentitymapping mappingforentityforname:@"usertest" inmanagedobjectstore:managedobjectstore]; [testcompletemapping addattributemappingsfromdictionary:@{ @"id": @"usertestid", }]; rkentitymapping *usertest_testmapping = [rkentitymapping mappingforentityforname:@"test" inmanagedobjectstore:managedobjectstore]; [usertest_testmapping addattributemappingsfromdictionary:@{ @"id": @"testid", @"begindate": @"begindate", @"expectedduration":@"expectedduration", @"finishdate": @"finishdate", }]; rkrelationshipmapping* usertest_test_relationship = [rkrelationshipmapping relationshipmappingfromkeypath:@"test" tokeypath:@"test" withmapping:usertest_testmapping]; //### groups rkentitymapping *grouptestmapping = [rkentitymapping mappingforentityforname:@"questiongroup" inmanagedobjectstore:managedobjectstore]; [grouptestmapping addattributemappingsfromdictionary:@{ @"id": @"groupid", @"number": @"number", @"text":@"text", }]; rkrelationshipmapping* group_test_relationship = [rkrelationshipmapping relationshipmappingfromkeypath:@"groups" tokeypath:@"groups" withmapping:usertest_testmapping]; //### add property mappings rkresponsedescriptor *completetestresponsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:testcompletemapping pathpattern:@"/api/module/demo2/lesson/phasellus/test/71" keypath:nil statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)]; [testcompletemapping addpropertymappingsfromarray:[nsarray arraywithobjects:usertest_test_relationship, nil]]; [usertest_testmapping addpropertymapping:group_test_relationship]; [objectmanager addresponsedescriptor:completetestresponsedescriptor];
i tried use "test.groups" instead of "groups" didn't work.
try code below. you're main issue appears typo (in definition of group_test_relationship
), missing identification attributes (not strictly required) code on correct path.
you didn't show definition of testcompletemapping
you'll need add , check typos.
//### test rkentitymapping *usertest_testmapping = [rkentitymapping mappingforentityforname:@"test" inmanagedobjectstore:managedobjectstore]; [usertest_testmapping addattributemappingsfromdictionary:@{ @"id": @"testid", @"begindate": @"begindate", @"expectedduration": @"expectedduration", @"finishdate": @"finishdate", }]; usertest_testmapping.identificationattributes = @[ @"testid" ]; //### groups rkentitymapping *grouptestmapping = [rkentitymapping mappingforentityforname:@"questiongroup" inmanagedobjectstore:managedobjectstore]; [grouptestmapping addattributemappingsfromdictionary:@{ @"id": @"groupid", @"text": @"text", }]; grouptestmapping.identificationattributes = @[ @"groupid" ]; [usertest_testmapping addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"groups" tokeypath:@"groups" withmapping:grouptestmapping]]; // complete 'testcompletemapping' here, adding 'test' relationship property mapping 'usertest_testmapping' if required //### add property mappings rkresponsedescriptor *completetestresponsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:testcompletemapping pathpattern:@"/api/module/demo2/lesson/phasellus/test/71" keypath:nil statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)]; [objectmanager addresponsedescriptor:completetestresponsedescriptor];
Comments
Post a Comment