Ios 来自nsmanagedObject的NSJSONSerialization表示密钥不符合键值编码

Ios 来自nsmanagedObject的NSJSONSerialization表示密钥不符合键值编码,ios,objective-c,json,core-data,nsjsonserialization,Ios,Objective C,Json,Core Data,Nsjsonserialization,我正试图将我的NSManagedObject作为序列化对象发送回我的Web服务。 我就是这样做的 NSDictionary *menuDictionary = [self dictionaryFromMenu:appointment]; NSError *err; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:menuDictionary options:NSJSONWritingP

我正试图将我的
NSManagedObject
作为
序列化对象发送回我的Web服务。
我就是这样做的

    NSDictionary *menuDictionary = [self dictionaryFromMenu:appointment];

        NSError *err;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:menuDictionary options:NSJSONWritingPrettyPrinted error:&err];

        NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                     encoding:NSUTF8StringEncoding];


- (NSDictionary *)dictionaryFromMenu:(Appointment*)appointment {
   NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[appointment.app_id description],@"Id",
     appointment.app_addressinfo, @"AddressInfo",
     appointment.app_completed, @"Completed",
     appointment.app_description, @"Description",
     appointment.app_end, @"EndDate",
     appointment.app_fullday, @"FullDay",
     appointment.app_label, @"Label",
     appointment.app_label_id, @"LabelId",
     appointment.app_location, @"Location",
     appointment.app_private, @"Private",
     appointment.app_project_name, @"ProjectName",
     appointment.app_project_number, @"ProjectNumber",
     appointment.app_relation_address_city, @"RelationAddressCity",
     appointment.app_relation_address_id, @"RelationAddressId",
     appointment.app_relation_address_name, @"RelationAddressName",
     appointment.app_relation_address_street, @"RelationAddressStreet",
     appointment.app_relation_code, @"RelationCode",
     appointment.app_relation_contact_id, @"RelationContactPersonId",
     appointment.app_relation_contact_name, @"RelationContactPersonName",
     appointment.app_relation_name, @"RelationName",
     appointment.app_reminder_info, @"ReminderInfo",
     appointment.app_start, @"StartDate",
     appointment.app_state, @"State",
     appointment.app_subject, @"Subject",
     appointment.app_supplier_code, @"SupplierCode",
     appointment.app_supplier_contact_person_id, @"SupplierContactPersonId",
     appointment.app_supplier_contact_person_name, @"SupplierContactPersonName",
     appointment.app_supplier_name, @"SupplierName",
     appointment.app_type, @"Type",
     nil];
    return dict;
}
这就是我的
实体的样子

现在我得到了这个错误:

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Appointment 0x16dcb520> valueForUndefinedKey:]: the entity Appointment is not key value coding-compliant for the key "SupplierName".'
***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:实体约会与密钥“SupplierName”的键值编码不兼容。”

有什么帮助吗?

所以SupplierName的值为零。这会导致词典的构建过早停止。如果使用了新的@{}语法,则会出现运行时错误


您需要更改代码,以便对于每个键,如果值为nil,您可以使用[NSNull null]来代替。

您最近是否添加了此属性或其他内容?可能您的数据库中有一些旧的数据格式,但不具有该属性。1)尝试从设备或模拟器中删除应用程序,然后重新启动应用程序。2) 也许这有助于您在收到错误时做什么?在创建字典后记录它,并仔细检查它是否与预期相符。您是否设置了异常断点以查明错误发生的确切位置?