Swift-crash EXC_BAD_ACCESS JSONDecoder与大JSON
我一直在用swift解码JSON 我在操场上得到了以下代码,其中包含一个JSON,它有10个字段。当我尝试解码数据时,我得到以下错误Swift-crash EXC_BAD_ACCESS JSONDecoder与大JSON,json,swift,jsondecoder,Json,Swift,Jsondecoder,我一直在用swift解码JSON 我在操场上得到了以下代码,其中包含一个JSON,它有10个字段。当我尝试解码数据时,我得到以下错误 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 re
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.
但是,如果我去掉例如“第九个”和“第十个”或任何其他字段中的2个,那么这个错误似乎不会发生,因此结构中只剩下8个字段
是否限制只能解码8个字段?我错过什么了吗?
我能做些什么来克服这个问题吗
我的代码片段:
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)")
对我有用。您使用的是什么版本的Xcode/Swift?版本12.0.1 Swift 5。2@NielsBeens你确定吗?Xcode 12随Swift 5.3一起提供。@DávidPásztor啊,是的,对不起,您的回答是正确的。这是swift 5.3这也被讨论过