【问题标题】:how to retrieve dictionary from firestore in c#如何在 C# 中从 Firestore 中检索字典
【发布时间】:2022-01-19 00:12:58
【问题描述】:

我正在尝试检索数据,他的类型是映射到 c# 中的组合框,但我失败了,我需要帮助 这是我的尝试

 async void GetSection()
    {
        DocumentReference docRef = database.Collection("Class").Document(combClasses.SelectedItem.ToString());
        DocumentSnapshot snapshot = await docRef.GetSnapshotAsync();
        if (snapshot.Exists)
        {
            //MessageBox.Show("Document data for {0} document:", snapshot.Id);
            Dictionary<string, object> city = snapshot.ToDictionary();
            foreach (KeyValuePair<string, object> pair in city)
            {
                if (pair.Key.Equals("Section"))
                {
                  
                }
            }
        }
        else
        {
            Console.WriteLine("Document {0} does not exist!", snapshot.Id);
        }           
    }

my firestore data

【问题讨论】:

  • 你的问题是什么?你被困在哪里了?
  • 我做到了,谢谢
  • 你解决了吗?您可以自行回答以分享您的解决方法,以帮助其他人
  • 好的,我现在就分享它

标签: c# firebase google-cloud-firestore


【解决方案1】:
 DocumentReference doc = database.Collection("Class").Document(combClasses.SelectedItem.ToString());
        DocumentSnapshot snap = await doc.GetSnapshotAsync();
        if (snap.Exists)
        {
            Dictionary<string, object> data = new Dictionary<string, object>();
            foreach (var item in snap.ToDictionary())
            {
                if (item.Key == "Section")
                {
                    foreach (var sec in (Dictionary<string, object>)item.Value)
                    {
                        data.Add(sec.Key, sec.Value);
                        
                            string ss = (sec.Key.ToString() + " # of student ( " + Convert.ToString(sec.Value.ToString()) + " )");
                            combSection.Items.Add(ss);                                                       
                    }
                }
            }
        }

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2013-06-06
  • 2013-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-01
  • 1970-01-01
相关资源
最近更新 更多