gpt4 book ai didi

ios - 来自 nsmanagedObject 的 NSJSONSerialization 表示键不符合键值编码

转载 作者:行者123 更新时间:2023-11-29 03:24:58 24 4
gpt4 key购买 nike

我正在尝试将我的 NSManagedObject 作为 Serialized object 发送回我的网络服务。我就是这样做的。

    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;
}

这就是我的实体的样子。

enter image description here

现在我得到这个错误:

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Appointment 0x16dcb520> valueForUndefinedKey:]: the entity Appointment is not key value coding-compliant for the key "SupplierName".'

有什么帮助吗?

最佳答案

所以 SupplierName 的值为 nil。这会导致字典的构建过早停止。如果您使用新的 @{} 语法,您将会遇到运行时错误。

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

关于ios - 来自 nsmanagedObject 的 NSJSONSerialization 表示键不符合键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20562805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com