ios - JSON 解码器 Swift 的潜在错误

标签 ios json swift encoder decoder

我相信我在 JSONDecoder 中发现了一个错误。如果尝试解码具有 8 个以上属性的 JSON 对象,我会收到一个无法识别的错误:

error: Execution was interrupted, reason: EXCBADACCESS (code=1, address=0xe8). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.


每当我执行类似于以下的代码时,就会发生此错误:
struct Objects: Codable {
  var NAME1: String?
  var NAME2: String?
  var NAME3: String?
  var NAME4: String?
  var NAME5: String?
  var NAME6: String?
  var NAME7: String?
  var NAME8: String?
  var NAME9: String?
}
let NEWDATA = """
[
{
  "NAME1": "hi",
  "NAME2": "hi",
  "NAME3": "hi",
  "NAME4": "hi",
  "NAME5": "hi",
  "NAME6": "hi",
  "NAME7": "hi",
  "NAME8": "hi",
  "NAME9": "HELLO"
}
]
""".data(using: .utf8)!
let decoder2 = JSONDecoder()
let product2 = try decoder2.decode([Objects].self, from: NEWDATA)
print(product2)
这发生在 Playground 和设备上。也许我做错了什么,但是当 Objects 结构中只有 8 个属性时它可以工作,但当你有 9 个或更多属性时就不行了。
Xcode 版本:12.1
swift 版本:5.3
感谢你的帮助!

最佳答案

注意到@TheSlyTurtle 你也提出了这个 JSONDecoder Limit Apple 开发者论坛上的问题。
另一位用户 Claude31 和我自己独立提出了对反馈助手的反馈。请参阅 FB9080056 和 FB9393489。
Apple 在 2021 年 7 月 27 日的回复如下:

Hi Max,

Thanks for your patience, and for your feedback. Please verify whether this is still an issue in Xcode 13 beta. There have been tools updates since this was filed, and this issue is not seen in our tests.

Please test with the latest betas, and then update your feedback report with your results by logging into https://feedbackassistant.apple.com or by using the Feedback Assistant app.

Xcode 13, macOS 12 and iOS 15 Betas and Release Candidates: https://developer.apple.com/download/

If the issue continues, please provide appropriate fresh logs and screen recordings: https://developer.apple.com/bug-reporting/profiles-and-logs/

Please close this report if resolved, or let us know if still an issue for you. Thank you.

Feedback ID 9080056, Playground Execution Abort With Struct On Ninth Property

Do not reply to this email. Please login to Feedback Assistant to view this request.


我和 Claude31 都表示,从 Xcode 13 beta 4 (13A5201i) 开始,此缺陷不再出现。

关于ios - JSON 解码器 Swift 的潜在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64598849/

相关文章:

ios - 错误: Generic parameter 'R.Generator.Element' cannot be bound to non-@objc protocol type 'AnyObject'

ios - 在 Xcode 8 中创建 .xib 启动屏幕

Swift Realm 只改变一个对象的值

swift - 在 NSTableView 中显示和使用核心数据

ios - 属性(property)不保值

ios - 隐藏状态栏不起作用的iOS

c# - 在 WCF 客户端中传递的多个参数不起作用(即使包装了 WebMessageBodyStyle)

ios - 从 JSON 数据添加到 UIButton 的 URL 链接

json - 如何使用 postman 创建新用户并在keycloak中分配组?

ios - 照片框架 : Connection to assetsd was interrupted or assetsd died