ios - 来自带有 Mantle : ignore a property 的 JSON 的对象

标签 ios github-mantle

我的应用程序从 JSON 创建一些 ObJC 对象。一切都工作正常,直到我向 ObjC 模型类添加了一个新属性,该属性在 JSON 中没有对应项。

我已按如下方式配置映射:

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"firstName"                   : @"firstname",
             @"middleName"                  : @"middlename",
             @"lastName"                    : @"lastname",
             // etc.
             @"phoneNumber"                 : NSNull.null // no JSON data for this one
             };
}

但是我在 Mantle 中遇到断言失败,位于 MTLJSONAdapter initWithModelClass :“phoneNumber 必须映射到 JSON 键路径或键路径的 JSON 数组,得到:null。

这就是我创建模型对象的方式:

MyData *myData = [MTLJSONAdapter modelOfClass:[MyData class] 
                           fromJSONDictionary:json error:&error];

我怎样才能拥有phoneNumber数据类中的属性没有映射到 JSON 值?

最佳答案

只是不要指定其映射到 + JSONKeyPathsByPropertyKey

关于ios - 来自带有 Mantle : ignore a property 的 JSON 的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31305909/

相关文章:

iphone - 地幔 :cannot find protocol declaration, 'MTLJSONSerializing'

ios - 地幔 : Uncaught exception 'NSInvalidArgumentException' when parsing JSON

objective-c - 在 iOS 上测试 Mantle 模型时出错

ios - 在 Swift 中测试我的应用程序时出错

ios - 默认导航栏高度ios

ios - UIView在用户交互后消失

ios - 如何让 YapDatabase 和 Mantle 很好地处理序列化

ios - UIRefresh 控件 endRefreshing 不起作用

IOS 连接到 BLE 设备 EXC_BREAKPOINT at didSelectRowAtIndexPath

ios - 如何使用 Mantle 省略 JSON 字典中的空值?