Arrays 当它不是json数组时如何使用ImmutableMappable
在github api中,json已经是一个数组,但在reddit api中不是Arrays 当它不是json数组时如何使用ImmutableMappable,arrays,json,swift,object,objectmapper,Arrays,Json,Swift,Object,Objectmapper,在github api中,json已经是一个数组,但在reddit api中不是 { "kind": "Listing", "data": { "modhash": "", "dist": 25, "children": [ { "
{
"kind": "Listing",
"data": {
"modhash": "",
"dist": 25,
"children": [
{
"kind": "t5",
"data": {
"user_flair_background_color": null,
"submit_text_html": null,
"restrict_posting": true,
"user_is_banned": null,
"free_form_reports": true,
"wiki_enabled": false,
"user_is_muted": null,
"user_can_flair_in_sr": null,
"display_name": "Home",
"header_img": null,
"title": "Home",
"allow_galleries": true,
"icon_size": null,
"primary_color": "",
"active_user_count": null,
"icon_img": "",
"display_name_prefixed": "r/Home",
}
},
}
如何映射这种json我有这段代码,当json已经是一个数组时,它就可以工作了
class Users: ImmutableMappable {
let title: String?
let display_name_prefixed: String?
init(map: Map) throws {
title = try map.value("title")
display_name_prefixed = try map.value("display_name_prefixed")
}
}
虽然它说对象映射失败了。请帮助一个正在努力学习的人
或者有什么方法可以使用objectMapper吗?这里的大多数人使用标准库中的
Codable
,因此值得研究。