4

I'm stuck on decoding a JSON in swift.

I've got the following code in a playground with a JSON that has 10 fields. When i try to decode the data I get the following Error

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

But this error does not seem to happen if I take out e.g. "ninth" and "tenth" or 2 of any of the other fields so only 8 fields remain in the struct.

Is there a limitation of only be able to have 8 fields decoded? Am I missing something? is there anything i can do to overcome this issue?

My code snippet:

let decoder = JSONDecoder()
struct Positions: Codable {
    let first : String
    let second: String
    let third: String
    let forth: String
    let fith: String
    let sixth: String
    let seventh: String
    let eigth: String
    let nineth: String
    let tenth: String
}

var positions = """
    {
    "first" : "first",
    "second": "second",
    "third": "third",
    "forth": "forth",
    "fith": "fith",
    "sixth": "sixth",
    "seventh": "seventh",
    "eigth": "eigth",
    "nineth": "nineth",
    "tenth": "tenth"
    }
""".data(using: .utf8)

    let result = try decoder.decode(Positions.self, from: positions!)
    print("tr \(result)")
  • 2
    Works for me. What version of Xcode/Swift are you using? – Sweeper Oct 30 '20 at 11:21
  • Version 12.0.1 swift 5.2 – Niels Beens Oct 30 '20 at 11:25
  • @NielsBeens are you sure about that? Xcode 12 comes with Swift 5.3. – Dávid Pásztor Oct 30 '20 at 11:28
  • @DávidPásztor ah yes sorry your correct. it's swift 5.3 – Niels Beens Oct 30 '20 at 11:29
  • hmm after switching in app to use swift 5 it does seems to be working fine. (app was not specified) It also works fine when trying it here http://online.swiftplayground.run/ on version 5.1 release. But does not work on 5.0 release. and also does not work in my playground on 5.3 – Niels Beens Oct 30 '20 at 11:45
  • I am also seeing the same issue. Crash happens using Xcode 12.0.1 playground, but works fine using 5.1 in online.swiftplayground.run. Seems like a possible Swift 5.3 regression? Would be worth opening a bug on [bugs.swift.org](https://bugs.swift.org). – Dávid Pásztor Oct 30 '20 at 11:47
  • 1
    This was also discussed [here](https://stackoverflow.com/questions/64598849/potential-bug-with-json-decoder-swift?noredirect=1#comment114223070_64598849) – Joakim Danielson Oct 30 '20 at 11:54

0 Answers0