gpt4 book ai didi

ios - 在 Swift 中将任何字典数组转换为字符串

转载 作者:可可西里 更新时间:2023-10-31 23:56:18 27 4
gpt4 key购买 nike

Convert [String:Any] dictionary array to [String:String] in Swift

我有一个字典数组 <String,Any>类型。现在我想转换为字符串,因为我想在 textField 中显示数据和文本字段不理解Any数据类型。

我的数据是这样的:

var myarr = [[String:Any]]()

[
[
"Area" : "",
"Good" : "-",
"Level" : 2,
"Link" : "<null>",
"Photo" : "-",
"Repair" : "-",
"Section" : "Others"
],

[
"Area" : "",
"Good" : "N",
"Level" : 2,
"Link" : "http://google.com",
"Photo" : 1,
"Repair" : "Y",
"Section" : "Grounds"
]

]

我想要新的数组字典:

var myarr = [[String:String]]()

最佳答案

map 是你的 friend ,也许是这样的

let stringDictionaries: [[String: String]] = myarr.map { dictionary in
var dict: [String: String] = [:]
dictionary.forEach { (key, value) in dict[key] = "\(value)" }
return dict
}

关于ios - 在 Swift 中将任何字典数组转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43730386/

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