Restkit嵌套对象映射失败

时间:2012-08-28 16:42:09

标签: objective-c restkit object-object-mapping

我要解析下面发布的嵌套JSON对象。它没有得到任何测试对象。我做错了什么?

{"tests":[{"type":"QA","list":[{"test_performed":{"id":11,"time":" 9:00 AM","tester":"Tester 1"}}]},{"type":"BAT","list":[]},{"type":"UAT","list":[]}],"tested":"true"}

创建的对象:

Result
NSArray *tests;
NSNumber *tested;

TestTypeList
NSArray *list;
NSString *type;

Test
NSNumber *identifier
NSString *start_time;
NSString *tester;

RKObjectMapping *testMapping=[RKObjectMapping mappingForClass:[Test class]];
[testMapping mapKeyPath:@"id" toAttribute:@"identifier"];
[testMapping mapKeyPath:@"time" toAttribute:@"time"];
[testMapping mapKeyPath:@"tester" toAttribute:@"tester"];
[[RKObjectManager sharedManager].mappingProvider setMapping:testMapping forKeyPath:@"test_performed"];

RKObjectMapping *testInverseMapping = [testMapping inverseMapping];
testInverseMapping.rootKeyPath = @"test_performed";

[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:timeInverseMapping forClass:[Time class]];

RKObjectMapping *testTypeListMapping=[RKObjectMapping mappingForClass:[TestTypeList class]];
[testTypeListMapping mapKeyPath:@"type" toAttribute:@"type"];
[testTypeListMapping mapKeyPath:@"list" toRelationship:@"list" withMapping:testMapping];

[[RKObjectManager sharedManager].mappingProvider testTypeListMapping forKeyPath:@"tests"];

RKObjectMapping *testTypeListInverseMapping = [testTypeListMapping inverseMapping];
testTypeListInverseMapping.rootKeyPath = @"tests";

[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:testTypeInverseMapping forClass:[TestTypeList class]];

RKObjectMapping *resultMapping=[RKObjectMapping mappingForClass:[Result class]];
[resultMapping mapKeyPath:@"tested" toAttribute:@"tested"];
[resultMapping mapKeyPath:@"tests" toRelationship:@"rides" withMapping: testTypeListMapping];

[[RKObjectManager sharedManager].mappingProvider setMapping:listMapping forKeyPath:@"result"];

RKObjectMapping *resultInverseMapping = [resultMapping inverseMapping];
resultInverseMapping.rootKeyPath = @"result";

0 个答案:

没有答案