我正在尝试解析以下json数据:
{
"id": 123,
"url": "https://www.google.com",
"title": "The Google link",
"created_at": "2017-08-29T04:00:00.000Z",
"sent": true,
"alternative": "https://google.com",
"things": [],
"description": [
"search",
"lookup"
],
"company": "Alphabet"
}
下面是我的结构:
struct site: Decodable {
let id: Int
let url: String
let title: String
let created_at: String
let sent: Bool
let alternative: String
let things: [String]
let description: [String]
let company: String
}
let sites = try JSONDecoder().decode(site.self, from: data)
我继续收到错误消息:
“ keyNotFound(CodingKeys(stringValue:” id“,intValue:nil),Swift.DecodingError.Context(codingPath:[],debugDescription:”没有与键CodingKeys相关联的值(stringValue:\“ id \”,intValue: nil)(\“ id \”)。”
这是由于json信息是数组吗?如何解析此信息?
感谢您提供任何反馈。对不起,我已更正标题以反映正确的错误。