import Foundation
struct PostsModel: Codable {
let posts: [Post]
}
struct Post: Codable {
let postID, timeshamp, likesCount: Int
let title, previewText: String
var timestampValue: String
enum CodingKeys: String, CodingKey {
case timeshamp, title
case postID = "postId"
case previewText = "preview_text"
case likesCount = "likes_count"
}
类型"Post"不符合协议"可解码">
如何修复?
CodingKeys中的变量名称与Post结构中的不同。
例如,使用:
case likesCount = "likesCount"