Iphone 使用magicalpanda'导入多关系数据;魔法记录

Iphone 使用magicalpanda'导入多关系数据;魔法记录,iphone,objective-c,ios,core-data,magicalrecord,Iphone,Objective C,Ios,Core Data,Magicalrecord,我想在Magic panda的MagicalRecord的帮助下,将一个json文件导入我的SQLite CoreData数据库。 这是我的json文件的内容: { "title":"Gebratener Schweinebauch auf dänische Art", "subtitle":"Stegt flaesk med persillesauce", "preparation_time":"35 Min.", "preparation_subtitle":"bei 225°C,

我想在Magic panda的MagicalRecord的帮助下,将一个json文件导入我的SQLite CoreData数据库。 这是我的json文件的内容:

{
 "title":"Gebratener Schweinebauch auf dänische Art",
 "subtitle":"Stegt flaesk med persillesauce",
 "preparation_time":"35 Min.",
 "preparation_subtitle":"bei 225°C, nicht vorheizen.",
 "components":[
  {
        "name":"Hauptgericht",
                "ingredients": [
       {
          "name":"1 kg geschälte und gekochte Kartoffeln"
       }
  ]
  }
 ]
}
- (void)initializeRecipeDatabase {
NSString *resource = [[NSBundle mainBundle]     pathForResource:kRecipeInitialDatabaseContentFilename 
                                                                                                         ofType:kRecipeInitialDatabaseContentFileType];
NSError *parsingError = nil;
NSDictionary *result = nil;

if (NSClassFromString(@"NSJSONSerialization")) {
    NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource];
    [inputStream open];

    result = [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:&parsingError];
}
else {
    NSData *jsonData = [NSData dataWithContentsOfFile:resource];
    result = [jsonData objectFromJSONData];
}

[Recipe MR_truncateAll];
[[NSManagedObjectContext MR_defaultContext] MR_save];
[Recipe MR_importFromDictionary:result];
[[NSManagedObjectContext MR_defaultContext] MR_save];


}
我正在尝试将文件内容导入以下核心数据模型: 数据模型的图像:

我使用以下代码导入json文件:

{
 "title":"Gebratener Schweinebauch auf dänische Art",
 "subtitle":"Stegt flaesk med persillesauce",
 "preparation_time":"35 Min.",
 "preparation_subtitle":"bei 225°C, nicht vorheizen.",
 "components":[
  {
        "name":"Hauptgericht",
                "ingredients": [
       {
          "name":"1 kg geschälte und gekochte Kartoffeln"
       }
  ]
  }
 ]
}
- (void)initializeRecipeDatabase {
NSString *resource = [[NSBundle mainBundle]     pathForResource:kRecipeInitialDatabaseContentFilename 
                                                                                                         ofType:kRecipeInitialDatabaseContentFileType];
NSError *parsingError = nil;
NSDictionary *result = nil;

if (NSClassFromString(@"NSJSONSerialization")) {
    NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource];
    [inputStream open];

    result = [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:&parsingError];
}
else {
    NSData *jsonData = [NSData dataWithContentsOfFile:resource];
    result = [jsonData objectFromJSONData];
}

[Recipe MR_truncateAll];
[[NSManagedObjectContext MR_defaultContext] MR_save];
[Recipe MR_importFromDictionary:result];
[[NSManagedObjectContext MR_defaultContext] MR_save];


}
导入工作时不会给我一个错误,但当我检查SQLite数据库的内容时,配料表中有两个相等的条目:

数据库内容的图像:


目前我有点无助于解决这个问题,如果有人能帮助我,我会非常高兴。

您在导入过程中发现了一个bug。目前有一个解决此问题的挂起解决方案。我有一个待处理的拉请求积压,但您可以查看一下,看看现在是否对您有帮助。

我尝试了对commit#8c0a084所做的更改,但这似乎无法解决我的问题。我仍然得到了成分实体的这两个条目:(我看到你已经将commit#8c0a084合并到master中-我已经提取了最新版本并再次测试了它,重复成分条目的错误仍然存在。我已经找到了解决这个问题的方法,你必须定义主键属性的名称(应确定您的实体的唯一性)在你的Relationshi-Attribute.Hi Sascha的用户信息部分,我和你有同样的需求。我需要从我创建的Web服务导入数据,并将它们保存到核心数据数据库。我刚刚找到MagicRecord库。如果你有时间,你能告诉我或给我看你使用几个rel插入数据时使用的代码吗关系?(我不明白这种关系应该如何与核心数据协同工作)?谢谢。。。