Ios Restkit尝试映射字段为string(包含一个Json字符串)的Json时崩溃

Ios Restkit尝试映射字段为string(包含一个Json字符串)的Json时崩溃,ios,objective-c,json,restkit,ironmq,Ios,Objective C,Json,Restkit,Ironmq,我正在发送一个包裹在iron mq消息中的json blob Restkit的主要功能是: { id:"2837409187409328", delay:60, body:"{ myJson:{ "hey":true}}" } Im使用rkrelationship将子对象映射为body:as类型CustomObject 但是,当Restkit尝试映射到该自定义对象时,它会崩溃,因为它将该“body”视为NSString而不是NSDictionary,并尝试使用sourceKeyPath从结果s

我正在发送一个包裹在iron mq消息中的json blob

Restkit的主要功能是:

{
id:"2837409187409328",
delay:60,
body:"{ myJson:{ "hey":true}}"
}
Im使用rkrelationship将子对象映射为body:as类型CustomObject

但是,当Restkit尝试映射到该自定义对象时,它会崩溃,因为它将该“body”视为NSString而不是NSDictionary,并尝试使用sourceKeyPath从结果sourceObject中获取值。。。但是因为它是一根绳子,它就爆炸了。与:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x7fcf91165060> valueForUndefinedKey:]: this class is not key value coding-compliant for the key alreadyLiked.'
***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:该类与密钥AlreadyLink的键值编码不兼容。”
我尝试使用动态映射并用NSDictionary替换表示

我尝试过按照文档中的建议对访问器进行验证,但从未调用过该代码。
有什么想法吗?

通过后处理解决。我最终获取了传递到body中的字符串,覆盖了该body属性的setter,在该setter中,我运行了一个映射操作来获取json字符串,并将其映射到我的自定义对象(转换为字典后),然后在我的父对象上设置它

希望这对你有帮助

//here I have an object with a string property called Body that contains JSON.
//I extract the json, turn it into a dictionary then map it to another property on that same object that actually has a relationship mapping...
//always check to see if the body actually exists before you try to map it 
//otherwise you will have a crash in your overridden setter..
if(self.Body){
        NSData *data = [self.Body dataUsingEncoding:NSUTF8StringEncoding];
        id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

        NSDictionary *representation = json;
        //NSDictionary *metadata = @{ @"URL": [NSURL URLWithString:@"http://restkit.org"]http://restkit.org"] };

        RKObjectMapping *objectMapping = [MyObject mapping];

        RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:representation destinationObject:mappedResultDTO mapping:objectMapping];

        RKObjectMappingOperationDataSource *dataSource = [RKObjectMappingOperationDataSource new];
        operation.dataSource = dataSource;
        // [operation start];

        NSError *error = nil;
        BOOL success = [operation performMapping:&error];
    }

这里发现了一个类似的问题:通过后期处理解决。最后,我获取了传递到body中的字符串,覆盖了该body属性的setter,并在setter中运行了一个映射操作来获取json字符串,并将其映射到我的自定义对象(在转换为字典之后)然后在我的父对象上设置它。请添加您的解决方案作为答案并接受:-)好了@Wain。包含代码和全部;)