我的 api 数据无法使用模型 swift 处理

my api data cannot process with model swift

这是我的模特。 quicktyper 网站翻译了我的模型


import  Foundation


struct User: Codable {
    let customerID, companyID: Int
    let firstName, lastName, phone, email: String
    let passwordHash, passwordSalt: JSONNull?
    let isStatus: Bool
}

struct Data : Codable{
    let custommodel : [User]
}

class JSONNull: Codable, Hashable {

    public static func == (lhs: JSONNull, rhs: JSONNull) -> Bool {
        return true
    }
    
    
    public var hashValue: Int {
        return 0
    }

    public init() {}

    public required init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if !container.decodeNil() {
            throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull"))
        }
    }

    public func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encodeNil()
    }
}

这是我的 api 请求


import Foundation



enum Verierror: Error{
    
    case noDatAvailable
    case canNotProcessData
    
}
struct verirequest{
    let resource : URL
    //example url. this is not the truth
    let resoucreString = ""
   
    init() {
       
        guard let resourceurll = URL(string: resoucreString) else {fatalError()}
        self.resource = resourceurll
    }
    
    
    func getveri(completion: @escaping(Result<[User],Verierror>) -> Void){
        let datatask = URLSession.shared.dataTask(with: resource) { data, _, _ in
            print(String(data: data!, encoding: .utf8))
            guard let jsondata = data else{
                completion(.failure(.noDatAvailable))
                
                return
            }
            do{
                let decoder = JSONDecoder()
                let veriresponse = try decoder.decode(Data.self, from: jsondata)
                let details = veriresponse.custommodel
               
                
                completion(.success(details))
            }catch{
                completion(.failure(.canNotProcessData))
            }
        }
        datatask.resume()
    }
    
}

我的数据来自 API,但无法处理我的数据。我收到“cannotprocesdata”错误。刚开始可以处理,现在不行了
我将我的模型翻译成 quictyper.com。同时,我在输出中收到错误“无法处理数据”。

api没有问题,可以在postman中测试。 问题可能出在我的模型上还是其他地方? 请帮助我

它是我的视图控制器


import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    @IBOutlet weak var tableview: UITableView!
 

    
    
    var listveri = [User]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableview.dataSource = self
        tableview.delegate = self
       
        
        let verirequest = verirequest()
        verirequest.getveri { [weak self] (result) in
            switch result{
            case.failure(let error):
                print(error)
            case.success(let data):
                self?.listveri = data
                DispatchQueue.main.async {
                    self?.tableview.reloadData()
                }
            }
        
        }
    
       
     
       
    }
   
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listveri.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
      
       
        
        cell.namelabel.text = listveri[indexPath.row].firstName
        cell.surnamelabel.text = listveri[indexPath.row].lastName
        cell.emaillabel.text = listveri[indexPath.row].email
        return cell
    }
    

  
 


}


尝试以下结构:

struct Response: Codable {
    let data: [User]   // <--- here
    let message: String?
    let success: Bool
}

struct User: Codable {
    let customerID, companyID: Int
    let firstName, lastName, phone, email: String
    let passwordHash, passwordSalt: String?
    let isStatus: Bool
}

并像这样解码服务器响应:

   let veriresponse = try decoder.decode(Response.self, from: jsondata)