0

我已经成功地手动将 json 字符串与托管对象映射,但我只是找不到如何将结果对象插入到我选择的托管对象上下文中。我是否必须创建一个 RKObjectManager 实例才能做到这一点?

NSMutableDictionary *area = [NSMutableDictionary dictionaryWithObject:dictionary forKey:@"restricted_position_detail"];
NSString* JSONString = [[DataProviderManager sharedManager] getJsonStringFromObject:area];
NSString* MIMEType = @"application/json";
NSError* error = nil;
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:MIMEType];
id parsedData = [parser objectFromString:JSONString error:&error];
if (parsedData == nil && error) {
    DLog(@"%@",error);
}

RKObjectMappingProvider* mappingProvider = [RKObjectManager sharedManager].mappingProvider;
[mappingProvider setMapping:[self getObjectMapping] forKeyPath:@"restricted_position_detail"];
RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
RKObjectMappingResult* result = [mapper performMapping];
if (result) {
    DLog(@"Yay! Mapping finished successfully");
}
else{
    DLog(@"Yay! Mapping failed");
}
4

1 回答 1

0

最后,我所要做的就是将 RKObjectMapper 实例 targetObject 属性设置为在好的 moc 中创建的对象!

于 2013-07-11T15:45:56.870 回答