gpt4 book ai didi

ios - 在 Swift 中访问深度嵌套的字典和数组值

转载 作者:可可西里 更新时间:2023-11-01 00:52:32 24 4
gpt4 key购买 nike

我有一组 super 嵌套的字典和数组

var lines = ["set0":["lines":["Line one","Line two"],"pickone": ["set1":"Apples","set2":"Oranges"]],"set1":["lines":["Line one","Line two"],"pickone":["set3":"Bananas","set4":"Grapefruits"]]]

我有两个问题:

  1. 有没有办法让那些嵌套字典的结构更具可读性

  2. 如何访问嵌套数组的值

例如,在 Playground 中,我正在尝试以下代码:

lines["set0"]!["lines"]

但我根本没有得到任何结果。

最佳答案

关于使其可读性的尝试:

var lines = [
"set0":[
"lines":[
"Line one",
"Line two"
],
"pickone":[
"set1":"Apples",
"set2":"Oranges"
]
],
"set1":[
"lines":[
"Line one",
"Line two"
],
"pickone":[
"set3":"Bananas",
"set4":"Grapefruits"
]
]
]

至于你的台词:

lines["set0"]!["lines"]

我可以确认它正在运行。也许你应该给 playground 一些时间来显示结果。或者,您可能忘记了:

import Foundation

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

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