Ios RestKit-将JSON内容保存到字符串coredata属性中
我需要解析一个JSON web服务响应,该响应包含一个其子项未知的键 例如,让我们使用以下JSON响应,其中customData属性的键是在运行时定义的:Ios RestKit-将JSON内容保存到字符串coredata属性中,ios,core-data,mapping,restkit,Ios,Core Data,Mapping,Restkit,我需要解析一个JSON web服务响应,该响应包含一个其子项未知的键 例如,让我们使用以下JSON响应,其中customData属性的键是在运行时定义的: { "score": 996, "customData": { "key1": "key1value", "key2": "key2value" }, "isRegistered": true, "allowOpening": "OK" } 是否可以将customData的JSON内容保存到string co
{
"score": 996,
"customData": { "key1": "key1value", "key2": "key2value" },
"isRegistered": true,
"allowOpening": "OK"
}
是否可以将customData的JSON内容保存到string coredata属性中
我尝试过这样一个简单的映射:
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:[[self class] description] inManagedObjectStore:managedObjectStore];
[mapping addAttributeMappingsFromDictionary:@{
@"score": @"score",
@"customData":@"customData",
@"isRegistered": @"isRegistered",
@"allowOpening": @"allowOpening"}];
但它不起作用,coredata保存的customData总是空的
非常感谢,,
丹
是否可以将customData的JSON内容保存到string coredata属性中
否,因为它将被反序列化为字典,并且没有将其转换为字符串的转换器
你可以把它存储为字典。您可以添加一个关系映射和一个动态映射,动态映射检查键是什么,并动态定义映射…谢谢您,Wain,动态映射可以是一个解决方案,但我不认为CoreData模型可以在运行时更改。事实上,它不能。只有当您有未知的源密钥和已知的目标密钥,并且源密钥来自类似的一组已知选项时,这才有效。