这是我打印的print(childSnap)
并尝试使用as? [String : Any]
进行解析,但总是失败。
Snap (-Ki9GkBvIMofJiIByVeI) {
location = Cupertino;
name = "find hotel ";
userCreatedId = "";
}
let ref = FIRDatabase.database().reference()
let allGroup = ref.child("all-group")
allGroup.observe(.childAdded, with: { (snapshot) in
for childSnap in snapshot.children{
print(childSnap)
if let _childSnap = childSnap as? [String : Any] {
//this code not execute..
let group = Group(json: _childSnap )
groups.append(group)
}
}
}, withCancel: nil)
}
答案 0 :(得分:1)
将广告childSnap
输入到FIRDataSnapshot
,然后访问它的value
属性。
if let _childSnap = (childSnap as! FIRDataSnapshot).value as? [String : Any] {
let group = Group(json: _childSnap )
groups.append(group)
}