我的jSON写得好吗?我只是有他们的细节框,我想在之后填充核心数据实体。 (顺便说一下,我需要一个简单的教程来设置我在coredata的数据,你有吗?cimgf的教程太复杂了或者我只是不理解它们:/
{
"boxes": {
"boxesDetail": [
{
"codeArticle": "WPCDE01C412L",
"nameBox": "boxName",
"texteMarketing": "boxTextMarketing",
"descriptionBox": "boxDescritpion",
"nbActivities": 1650,
"kindBox": "boxKind",
"typeBox": "boxType",
"priceBox": 20,
"dlu": 2014,
"note": 3
},
{
"codeArticle": "BOOYAKA!!",
"nameBox": "boxNameName",
"texteMarketing": "boxTextMarketing",
"descriptionBox": "boxDescritpion",
"nbActivities": 1650,
"kindBox": "boxKind",
"typeBox": "boxType",
"priceBox": 39,
"dlu": 2014,
"note": 3
}
]
}
}
答案 0 :(得分:1)
正如JeremyP所说,你应该使用JSON Parser来检查你的JSON。我还完全建议jsonlint.com检查JSON。
就CoreData的简单教程而言,我建议Ray Wenderlich's tutorial。它已针对iOS 5进行了更新,因此可能有更新的教程将帮助您了解。我还没有完成更新的教程,但我很确定这是我在学习CoreData时在iOS 5之前看过的那个。
在查看了CoreData教程并了解它并理解它之后,我会在你的Box上写一个帮助函数作为一个类别。
的内容
+ (id)boxWithDictionary:(NSDictionary *)dict withManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;
{
Box *box = [NSEntityDescription insertNewObjectForEntityForName:@"Box"
inManagedObjectContext:managedObjectContext];
box.codeArticle = [dict objectForKey:@"codeArticle"];
box.nameBox = [dict objectForKey:@"nameBox"];
box.texteMarketing = [dict objectForKey:@"texteMarketing"];
box.descriptionBox = [dict objectForKey:@"descriptionBox"];
box.nbActivities = [dict objectForKey:@"nbActivities"];
box.kindBox = [dict objectForKey:@"boxKind"];
box.typeBox = [dict objectForKey:@"boxType"];
box.priceBox = [dict objectForKey:@"priceBox"];
box.dlu = [dict objectForKey:@"dlu"];
box.note = [dict objectForKey:@"note"];
return box;
}
将此代码放在一个类别和单独文件中的Xcode生成的Box.m和Box.h文件的原因是,如果您在CoreData中编辑Box实体并且必须生成新文件,它不会用你的帮助函数覆盖这个类别文件。
我希望这会有所帮助。