gpt4 book ai didi

swift - 使用区分子节点从 Firebase 检索节点

转载 作者:行者123 更新时间:2023-11-28 11:34:35 26 4
gpt4 key购买 nike

我有以下 json 树:

{
"workout" : {
"Monday, 22 Apr, 2019" : {
"exercise" : {
"Chest Press Machine" : {
"-Ld5FCV-q_pnPvT9MICU" : {
"reps" : "10",
"set" : "1",
"weight" : "70"
},
"-Ld5FJDqxepyhCN3twrM" : {
"reps" : "8",
"set" : "2",
"weight" : "75"
}
},
"Decline Dumbbell Bench Press" : {
"-Ld5SCZhUpmrnBYhw-xK" : {
"reps" : "8",
"set" : "1",
"weight" : "24"
}
},
"Incline Barbell Bench Press" : {
"-Ld3wdB0mKZB9hEJ_9gF" : {
"reps" : "8",
"set" : "1",
"weight" : "55"
}
}
}
},
"Saturday, 27 Apr, 2019" : {
"exercise" : {
"Decline Dumbbell Flyes" : {
"-LdTqpAEpVaE8VHVH_Hq" : {
"reps" : "10",
"set" : "1",
"weight" : "10"
}
}
}
}

如何从不同日期的每个锻炼类(class)中检索锻炼名称,即“胸部推举机”和“下斜哑铃卧推”?我的目标是在数组“exerciseList”中对这些值进行排序。

到目前为止,我已经使用下面的代码检索了某个日期内的练习,但我不知道如何定位名称。

refExerciseList.child("workout").observe(DataEventType.value, with: {(snapshot) in
let items = snapshot.value as! [String: Any]
print(snapshot)
for i in Array(items.values){
print(i)
}
})

提前致谢。

最佳答案

你可以试试

var exerciseList = [String]()
refExerciseList.child("workout").observe(DataEventType.value, with: {(snapshot) in
let items = snapshot.value as! [String: [String:[String:Any]]]
print(snapshot)
for i in Array(items.values){
for inner in Array(i.values){
exerciseList += Array(inner.keys)
}
}
})

关于swift - 使用区分子节点从 Firebase 检索节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55883157/

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