gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:30:23 25 4
gpt4 key购买 nike

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

error: Execution was interrupted, reason: EXCBADACCESS (code=1,address=0xe8). The process has been left at the point where it wasinterrupted, use "thread return -x" to return to the state beforeexpression 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 verifywhether this is still an issue in Xcode 13 beta. There have been toolsupdates since this was filed, and this issue is not seen in our tests.

Please test with the latest betas, and then update your feedbackreport with your results by logging intohttps://feedbackassistant.apple.com or by using the Feedback Assistantapp.

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 andscreen recordings:https://developer.apple.com/bug-reporting/profiles-and-logs/

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

Feedback ID 9080056, Playground Execution Abort With Struct On NinthProperty

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


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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com