【问题标题】:error is The data couldn’t be read because it isn’t in the correct format错误是无法读取数据,因为它的格式不正确
【发布时间】:2021-03-04 13:01:40
【问题描述】:

请谁能帮我解决这个问题。我已经坚持了好几个小时了

网址是“https://pryaniky.com/static/json/sample.json”

[我的模特图片.swift 我似乎无法理解为什么它的格式不正确.. 我将非常感谢任何帮助。 感谢期待

【问题讨论】:

  • 您应该将代码添加为代码,而不是发布代码的图像。您还需要向我们展示您的 [Empty] 模型。
  • print("error is \(error)") 而不是使用localizedDescription
  • 这是我的空模型结构 Empty: Codable { var data: [Datum]?变量视图:[字符串]? } // MARK: - Datum struct Datum: Codable { var name: String? var 数据:数据类? } // MARK: - DataClass struct DataClass: Codable { var text: String?变量网址:字符串? var selectedID:整数? var 变体:[变体]? enum CodingKeys: String, CodingKey { case text, url case selectedID case variables } } // MARK: - Variant struct Variant: Codable { var id: Int? var 文本:字符串? }
  • 嗨拉姆。当我使用 print("error is (error)" error is typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a字典代替。”,基础错误:无))

标签: json swift alamofire


【解决方案1】:

我修好了 我的坏

只是在 ApiHandler 中将 [Empty] 改为 Empty

【讨论】:

    猜你喜欢
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 2018-04-06
    相关资源
    最近更新 更多