【发布时间】:2013-07-01 08:27:57
【问题描述】:
如何从 Core Data 实体及其 1:m 子实体中创建带有 NSJSONSerialization 的 JSON 对象?
当尝试在将提取请求转换为 JSON 之前将其输出到 NSDictionary 时,我得到一个没有任何关系的平面 NSDictionary,或者在将 propertiesToFetch 设置为关系时我的应用程序崩溃。
这是我的代码:
NSFetchRequest *request = [NSFetchRequest
fetchRequestWithEntityName:@"ContrSector"];
request.resultType = NSDictionaryResultType;
request.propertiesToFetch = @[@"industries"];
NSError *error;
NSArray *result = [self.managedObjectContext
executeFetchRequest:request error:&error];
这样做的正确方法是什么?
【问题讨论】:
标签: ios objective-c json core-data nsdictionary