JSON API - 卡在“预期解码数组<Any> 但找到了字典

JSON API - Stuck with "Expected to decode Array<Any> but found a dictionary instead

现在使用 decodable 等通常还不错,但这个真的让我很困惑。我有一个 API returns 以下响应

{
    "data": {
        "contentResults": [{
            "id": 2,
            "title": "news report 1",
            "imageUrl": "www.image.com"
        }, {
            "id": 1,
            "title": "news report 2",
            "imageUrl": "www.image.com"
        }]
    }
}

让我感到困惑的是数据对象中的数组,我似乎无法正确解码它。

这是我的解码结构

struct TopLevel: Codable { 

    let contentResults: [contentResults]

    

    enum CodingKeys: String, CodingKey {

        case contentResults

    }

}



struct contentResults: Codable {

    public var title: String

    public var imageUrl: String

    

    enum CodingKeys: String, CodingKey {

        case title = "title"

        case imageUrl = "imageUrl"

    }

}

Xcode 一直给我错误“预期解码数组,但找到了一本字典”,我知道这是什么意思,但我已经用头撞墙几个小时了所以想要一些帮助。我已经引用了这个特定页面 虽然它对我有一点帮助,但并没有让我越过这条线

感谢任何帮助。干杯

您缺少解析“数据”的部分:

struct DataResponse: Codable {
let data: TopLevel 
}