Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift-crash EXC_BAD_ACCESS JSONDecoder与大JSON_Json_Swift_Jsondecoder - Fatal编程技术网

Swift-crash EXC_BAD_ACCESS JSONDecoder与大JSON

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

我一直在用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 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这也被讨论过