私のエンティティが空である理由を教えてください。
エンティティに JSON を入力しています。エンティティの属性の名前は JSON と同じです
これは私のエンティティにデータを入力するための私のコードです:
NSManagedObjectContext *cxt = [self managedObjectContext];
NSManagedObject *newBoxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:cxt];
NSDictionary *parsedFeed = [[newBoxes entity] attributesByName];
for (NSString *key in parsedFeed) {
id value = [parsedFeed objectForKey:key];
// Don't assign NSNull, it will break assignments to NSString, etc.
if (value && [value isKindOfClass:[NSNull class]])
value = nil;
@try {
[Boxes setValue:value forKey:key];
} @catch (NSException *exception) {
// Exception means such attribute is not defined in the class or some other error.
}
}
NSError *err;
if (![cxt save:&err]) {
NSLog(@"An error has occured: %@", [err localizedDescription]);
}
NSLog(@"ENTITY %@", newBoxes);
これは私の NSLOG の結果です:
2012-04-30 11:16:23.352 Wonder[9987:fb03] ENTITY <Boxes: 0x6d87330> (entity: Boxes; id: 0x6d8b010 <x-coredata://EFDCC0BA-644D-42AC-8DE8-452F02B7C680/Boxes/p26> ; data: {
codeArticle = nil;
descriptionBox = nil;
dlu = 0;
kindBox = nil;
nameBox = nil;
nbActivities = 0;
note = 0;
priceBox = 0;
texteMarketing = nil;
typeBox = nil;
})
これは私のJSONです:
{
"totalBox":{
"boxes":[
{
"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
}
]
}
}
これは私のエンティティです:
編集:私はJSONを与えるので、コアデータにエンティティを入力するために何を読むべきかを「伝える」必要がありますよね?
dataToDisplay = [[NSMutableArray alloc] init];
//récupération du chemin vers le fichier contenant le JSON
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"JSON" ofType:@"txt"];
//création d'un string avec le contenu du JSON
NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
//Parsage du JSON à l'aide du framework importé
NSDictionary *json = [myJSON JSONValue];
//récupération du total des Boxes
NSDictionary *resultats = [json objectForKey:@"totalBox"];