gpt4 book ai didi

ios - 地幔 iOS : How to create class model with variable key

转载 作者:行者123 更新时间:2023-11-29 12:14:28 28 4
gpt4 key购买 nike

我有一个 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 模型都有固定的键,所以我不知道如何处理这种特殊情况。

有什么想法吗?

最佳答案

你有几个选择:

  • 更改服务器端 API 以返回嵌套在键中的字典 ({"property": { "111": …, "222": … }}) 这样你就可以实际绑定(bind)到它
  • 在解析之前修改客户端的响应

一旦你有了一个可以在 +JSONKeyPathsByPropertyKey 中传递的值,你就可以编写一个自定义值转换器来处理模型。

这里有两个例子可以帮助您入门:

最重要的部分是弄清楚您希望如何使用从 JSON 获取的 map 。也许你最好将它作为字典保存在私有(private)属性中,并编写公共(public)方法以一种有意义的方式访问它

关于ios - 地幔 iOS : How to create class model with variable key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32337899/

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