问题描述
我试图找出我的 JSON 解码出了什么问题。我总是得到同样的错误:“预期解码 Dictionary
import Foundation
let json = """
[{
"Meta": {
"id": "above:1","uuid": "f9ccfcaa-836c-4402-b2e8-5ef6e0f13eac","src": "int_dict","section": "alpha","stems": ["above"],"offensive": false
}
}
]
"""
struct Word: Decodable {
let Meta: [String]
let id: String
let uuid: String
let src: String
let section: String
let stems: [String]
let offensive: Bool
}
let jsonData = json.data(using: .utf8)!
let decoder = JSONDecoder()
let word = try decoder.decode(Word.self,from: jsonData)
print (word)
我遇到了同样的错误:
Playground execution terminated: An error was thrown and was not caught:
▿ DecodingError
▿ typeMismatch : 2 elements
- .0 : Swift.Dictionary<Swift.String,Any>
▿ .1 : Context
- codingPath : 0 elements
- debugDescription : "Expected to decode Dictionary<String,Any> but found an array instead."
- underlyingError : nil
错误是什么?
谢谢
以利
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)