嗨,我有一个给定格式的JSON
"exclusions": [
[
{
"facility_id": "1",
"options_id": "4"
},
{
"facility_id": "2",
"options_id": "6"
}
],
[
{
"facility_id": "1",
"options_id": "3"
},
{
"facility_id": "3",
"options_id": "12"
}
],
[
{
"facility_id": "2",
"options_id": "7"
},
{
"facility_id": "3",
"options_id": "12"
}
]
]
我正在使用Object Mapper
库解析JSON
,但据我所知,我觉得它缺少一个键,因为关键exclusions
下的每个对象都是一个数组,无论如何我可以使用ObjectMapper解析它
为什么不Codable
class Root:Codable {
let exclusions:[[InnerItem]]
}
class InnerItem:Codable {
let facilityId:String
let optionsId:String
private enum CodingKeys: String, CodingKey {
case facilityId = "facility_id"
case optionsId = "options_id"
}
}
//
do {
let decoded = try JSONDecoder().decode(Root.self, from:jsonData)
print(decoded)
} catch {
print(error)
}
顺便说一句,你的json需要一个周围的{}