gpt4 book ai didi

ios - 访问字典数组的嵌套数组

转载 作者:行者123 更新时间:2023-11-30 11:14:12 25 4
gpt4 key购买 nike

我想在 TableView 上显示“描述”的值,但无法访问“描述”。每次我都会循环播放。示例

for i in item { 
let result = i["description"]
}

它返回类型“Any”没有下标成员

[[["description": "Meeting", "comments": "", "projectId": 6, "hours": 0.0, "id": 52, "projectName": "A-DA Internal"], ["description": "Others", "comments": "", "projectId": 6, "hours": 0.0, "id": 53, "projectName": "A-DA Internal"], ["description": "3.1 Project Planning", "comments": "", "projectId": 5, "hours": 0.0, "id": 28, "projectName": "STARWorks ESS"], ["description": "4.1 Analysis & Design", "comments": "", "projectId": 5, "hours": 0.0, "id": 32, "projectName": "STARWorks ESS"], ["description": "4.3 Bug fixes", "comments": "", "projectId": 5, "hours": 0.0, "id": 34, "projectName": "STARWorks ESS"]]]

最佳答案

从您上面发布的响应来看,类型似乎是[[[String : Any]]]。因此,要到达 [String: Any] 部分,您必须深入两个级别。

//let say
let result: [[[String: Any]]] = THE RESPONSE YOU POSTED..

let item = result.flatmap {$0} //this will convert to [[String: Any]]

//After that your loop will work as expected

for i in item {
debugPrint(i["description"])
}

关于ios - 访问字典数组的嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51892935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com