ios - RestKit - 将 JSON 内容保存到字符串核心数据属性中

标签 ios core-data mapping restkit

我需要解析一个 JSON 网络服务响应,其中包含一个其子项未知的 key 。

例如,我们有以下 JSON 响应,其中 customData 属性的键是在运行时定义的:

{
    "score": 996,
    "customData": { "key1": "key1value", "key2": "key2value" },
    "isRegistered": true,
    "allowOpening": "OK"
}

是否可以将 customData 的 JSON 内容保存到字符串 coredata 属性中?

我试过像这样的简单映射:

RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:[[self class] description] inManagedObjectStore:managedObjectStore];
[mapping addAttributeMappingsFromDictionary:@{
                 @"score": @"score",
                 @"customData":@"customData",
                 @"isRegistered":  @"isRegistered",
                 @"allowOpening": @"allowOpening"}];

但是不行,coredata保存的customData一直是空的。

非常感谢, 丹

最佳答案

Would it be possible to save the JSON content of customData into a string coredata attribute?

不,因为它将被反序列化为一个字典,并且没有将其转换为字符串的转换器。

您可以将其存储为字典。您可以使用动态映射添加关系映射,动态映射检查键是什么并动态定义映射...

关于ios - RestKit - 将 JSON 内容保存到字符串核心数据属性中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33779998/

相关文章:

ios - 滚动内部 UITableView 时处理 NSNotification

ios - 如何在 Ionic 应用程序中添加后台服务

ios - 布局/方向更改后的 Cordova iPhone X 安全区域。

ios - SKShapeNode 拖动不流畅

ios - 核心数据后台保存性能问题

ios - 以编程方式为 iOS 的核心数据属性(列)设置默认值

c# - 让 2 个不同的映射文件在同一个域中工作

ios - 如何更新托管对象数据?

elasticsearch - 查询 Elasticsearch 基于地址的索引

symfony - 从 ODM(文档、MongoDB)中引用具有多对多关系的 ORM(实体)