json - Swift - 使用大 JSON 使 EXC_BAD_ACCESS JSONDecoder 崩溃
问题描述
我坚持快速解码 JSON。
我在一个带有 10 个字段的 JSON 的操场上得到了以下代码。当我尝试解码数据时,出现以下错误
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)")
解决方案
推荐阅读
- express - 使用 NextJS 9 即时返回 PDF
- azure-blob-storage - Azure Blob 用户操作日志记录
- java - 从 AsyncTask 将数据返回到 MainActivity 的最佳方法
- tsql - 如何优化从两个表中的一个或另一个中获取的 T-SQL 查询
- python - 按字符串列表的顺序解析 Pandas 数据帧
- sql - Oracle 数据库 - MV 快速刷新、引用视图
- loops - 遍历游标
- javascript - 我们如何使用茉莉花模拟私有方法?
- react-native - 我如何通过贝宝在 React Native 中实现汇款?
- typescript - Typescript: How type a function using generic type in this case?