Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
835 views
in Technique[技术] by (71.8m points)

ios - Potential Bug with JSON Decoder Swift

I believe I have found a bug in the JSONDecoder. If one tries to decode a JSON object with more than 8 properties, I get an unrecognizable error:

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.

This error happens whenever I execute code similar to below:

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)

This happens in both the Playground and on the device. Maybe I am doing something wrong but it works when you have only 8 properties in the Objects struct but not when you have 9 or more.

Xcode Version: 12.1

Swift Version: 5.3

Thanks for all your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Noted @TheSlyTurtle that you also raised this JSONDecoder Limit issue on Apple Developer Forums.

Another user Claude31 and myself independently raised feedback on Feedback Assistant. See FB9080056 and FB9393489.

Apple replied on this 27 July 2021 as follows:

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.

Both myself and Claude31 stated that as of Xcode 13 beta 4 (13A5201i) this defect no longer manifests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...