gpt4 book ai didi

ios - iOS 中的 Alamofire 正在接收字典而不是数组

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:49 24 4
gpt4 key购买 nike

我正在 iOS 中创建表格,并且应该以 JSON 数组的形式接收所需的数据。但是,当我在我的 iOS 应用程序中获取数据时,它显示为未排序的字典。我能够在 Postman 中运行 GET 请求并正确接收数据,但是当我在我的 iOS 应用程序中通过 Alamofire 接收它时,它的格式不正确。 Alamofire 是否有可能以某种方式重新格式化 JSON 并将所有数组转换为字典,我可以以某种方式覆盖该设置吗?

这是 Postman 中 JSON 的列部分的示例:

enter image description here

这是我通过 Alamofire 收到的信息:

enter image description here

这就是我尝试访问 JSON 的方式

if let jsonColumns = json["columns"] as? [[String:Any]] {
for columns in jsonColumns {
for column in columns.values {
if let c = column as? [String:Any] {
if c["isVisible"] as? Bool == false {
continue
}
if let columnName = c["name"] as? String {
dataSet.columns.append(columnName)
}
}
}
}
}

最佳答案

两个图像中的 JSON 结构是相同的,你有 columns 这是一个字典数组 ([[String: Any]]) 只有一个元素。

字典中的值没有排序,因为它们是通过键访问的,而不是通过值循环访问的。

来自 here :

A dictionary stores associations between keys of the same type and values of the same type in a collection with no defined ordering. Each value is associated with a unique key, which acts as an identifier for that value within the dictionary. Unlike items in an array, items in a dictionary do not have a specified order. You use a dictionary when you need to look up values based on their identifier, in much the same way that a real-world dictionary is used to look up the definition for a particular word.

关于ios - iOS 中的 Alamofire 正在接收字典而不是数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57207511/

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