我需要在 swift 4 中使用可编码来解析二维数组,请告诉我该怎么做。以下是我的代码剪断
var exclusive = “””
{“list”:[[{“primary_key”:”1",”foreign_key”:”3"},{“primary_key”:”2",”foreign_key”:”10"}],[{“primary_key”:”2",”foreign_key”:”10"},{“primary_key”:”3",”foreign_key”:”22"}]]}
“””
let exeString = try! exclusive.data(using: .utf8)
struct ListStruct : Codable {
struct listStruct :Codable {
let primary_key : Int
let foreign_key : Int
}
let list = [[listStruct]] ()
or
let list = [][listStruct]
}
let listofData = try! JSONDecoder().decode(ListStruct.self, from: exeString!)