"Stores", -> "A-6ren">
gpt4 book ai didi

arrays - 字典,其中值包含字典,值包含数组

转载 作者:行者123 更新时间:2023-11-28 15:42:52 25 4
gpt4 key购买 nike

我一直在寻找一段时间没有成功,需要一个答案。

我正在寻找的数据结构是一个具有键和值的字典。该值是字典,并有一个数组作为值。

例如:

"San Francisco" -> "Stores", -> "Apple Store", "...", ".." 
"Companies" -> "...", ".."
"New York" -> "Fast Food" -> "Mc", "BK", "KFC"

我怎样才能做到这一点?

我试过

var nest = [String: [String: [String]]]()
nest["New York"]["Fast Food"] = ["MC", "BK"]

这似乎无法正常工作。

但是,我可以做到这一点

var fastfood = [String: [String]]()
var names = [String]()

fastFood["Fast Food"] = names
nest["New York"] = fastFood

这会引起问题。我每次都需要创建一个对象。我正在从数据库中获取数据,需要将传入的数据直接附加到嵌套中。

最佳答案

如何创建可帮助您管理数据分类的小型数据结构。

例子:

struct CityTaxonomy {
let city: String
let taxonomy: [String:[String]]
}

CityTaxonomy(city: "San Francisco", taxonomy: ["Stores":["Apple Store", "...", ".."],"Companies":["...", ".."]])

关于arrays - 字典,其中值包含字典,值包含数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43519170/

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