如何从Firebase中检索数据

您好,我已经尝试了几种方法,但基本上,我有我的firebase数据库中使用Python上传的数据的数组。 在Python中,我将所有东西都添加到数组中,并将其上传到数据库。 在Swift中我试图检索这样的数据

import UIKit import Foundation import Firebase class CSGOView: UIViewController, UITableViewDelegate, UITableViewDataSource{ var teams: [String] = [] var times: [String] = [] @IBOutlet weak var tableViewTwo: UITableView! let ref = FIRDatabase.database().reference(fromURL: "Took the url out it is the right url to the database im sure") override func viewDidLoad() { super.viewDidLoad() getTeamsAndTimes() } func getTeamsAndTimes() { //let userID = FIRAuth.auth()?.currentUser?.uid ref.child("Teams").observeSingleEvent(of: .value, with: { (snapshot) in // Get user value let value = snapshot.value as? [String: String] ?? [:] for team in value { print(team.key) print(team.value) } // ... }) { (error) in print(error.localizedDescription) } } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell? = nil return cell! } } 

这不起作用,虽然当视图加载没有什么打印到控制台。 我有在ViewDidLoad()中运行的方法。

这里是如何在firebase数据库中的数据(我必须去所以我会上传,当我回来)大致是这样的

球队0:“队名”1:“teamtwo”

所以有团队然后加号,并下降显示一个字典0作为关键和“团队名称”的价值。 如果有帮助,我没有在键和值之前的随机ID。 我使用set方法而不是python中的push方法。 set方法上传没有id的数据。

原来我不能上传图像,直到我有10代表。

https://ibb.co/dSp5ka

上面的链接将向您介绍Firebase数据库的外观

在JavaScript中,您可以直接提供对firebaseArray的引用,并从Firebase获取数组的值。

  var TeamRef = ref.child('Teams'); var TeamInfo = $firebaseArray(TeamRef); 

不确定关于Swift / Python。

希望这可以帮到你

 let value = snapshot.value as? [String: String] ?? [:] for team of value { print(team.key) print(team.value) } 

根据您在上述post中提供的信息; 这是我能说的最好的 –

安全规则

 { "rules": { ".write" : "auth != null", ".read" : "auth != null", "Teams" :{ ".read" : "true", // Make it publicly accessible ".write" : "true", } } } 

 var dict = NSMutableDictionary() // Global Declaration FIRDatabase.database().reference().child("shows").observeSingleEvent(of: .value, with: {(Snapshot) in for each in Snapshot.children{ self.dict.setObject((each as! FIRDataSnapshot).value as! String, forKey: String((each as! FIRDataSnapshot).key) as! NSCopying) print(self.dict) } })