我已经成功地手动将 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");
}