我正在尝试访问 json 文件中的数据,但不完全确定如何访问。我正在尝试访问此 json 中的“animation_file”:
"items": [{
"newUser": {
"steps": [
{
"id": 0,
"step_title": "stepConcept",
"visible": false,
"animation_file": "Welcome_Step_01_V01"
},
{
"id": 1,
"step_title": "stepSafety",
"visible": true,
"animation_file": "Welcome_Step_02_V01"
},
{
"id": 2,
"step_title": "stepFacilitator",
"visible": true,
"animation_file": "Welcome_Step_03_V01"
},
{
"id": 3,
"step_title": "stepTransparency",
"visible": true,
"animation_file": "Welcome_Step_04_V01"
}
]
},
这是我到目前为止所拥有的:
guard let items = welcomeJSON["items"] as? [[String:Any]] else {return}
for item in items {
if (isNewUser) {
if let newUser = item["newUser"] as? [String:Any] {
if let steps = newUser["steps"] as? [[String:Any]] {
for embeddedDict in steps {
for (key, value) in embeddedDict {
if let val = value as? Bool, val == true {
print(key)
newUserViews.append(key)
}
}
}
} else {
listOfViews = newUserViews
listOfViews = [STEP_CONCEPT, STEP_SAFETY, STEP_FACILITATOR, STEP_TRANSPARENCY]
maxPages = listOfViews.count
return
}
}
}
这看起来正确吗?我觉得我可能错过了一步。