作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 JSON 字典,如下所示:
{
"111": {"dates" : [<array_of_dates>],
"members" : [<array_of_members>]},
"112": {"dates" : [<array_of_dates>],
"members" : [<array_of_members>]},
"113": {"dates" : [<array_of_dates>],
"members" : [<array_of_members>]}
}
如您所见,嵌套字典的键是可变的 (111, 112, 113)。
到目前为止,我制作的每个 Mantle 模型都有固定的键,所以我不知道如何处理这种特殊情况。
有什么想法吗?
最佳答案
你有几个选择:
{"property": { "111": …, "222": … }}
) 这样你就可以实际绑定(bind)到它一旦你有了一个可以在 +JSONKeyPathsByPropertyKey
中传递的值,你就可以编写一个自定义值转换器来处理模型。
这里有两个例子可以帮助您入门:
mtl_arrayMappingTransformerWithTransformer
https://github.com/Mantle/Mantle/blob/master/Mantle/NSValueTransformer%2BMTLPredefinedTransformerAdditions.m#L106-L229 最重要的部分是弄清楚您希望如何使用从 JSON 获取的 map 。也许你最好将它作为字典保存在私有(private)属性中,并编写公共(public)方法以一种有意义的方式访问它
关于ios - 地幔 iOS : How to create class model with variable key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32337899/
我是一名优秀的程序员,十分优秀!