使用Xamarin Android从Firebase数据库检索阵列

时间:2019-02-11 20:44:00

标签: android visual-studio firebase xamarin firebase-realtime-database

在firebase数据库中,我有保姆,它由字符串和数组组成,可用性在firebase中是这样的:

{"babysitter": {
   {"-UserID" : {
    "Address": " djsh",
    "Age": "26",
    "Availability": [
      0: "Monday Morning",
      12: "Saturday Afternoon",
      18: "Friday Evening"
      19: "Saturday Evening"
      27: "Sunday Night" ],

     "City": "hjhj",
     "Eircode": "djsahdja",
     "Name": "jenna",
     "Email": "dkajk@dsj"
    },
{"-UserID": {
    "Address": " kokjk",
    "Age": "29",
    "Availability": [
      0: "Monday Night",
      12: "Tuesday Afternoon",
      18: "Friday Evening"
      19: "Saturday Morning"
      27: "Sunday Night" ],

     "City": "kjdsakhd",
     "Eircode": "nkkj7",
     "Name": "paul",
     "Email": "kljk@djks"
    }
  }
}

在Xamarin Android Visual Studio 2017中使用以下代码开始将数组中的数据存储在Firebase中之前,我可以检索所有数据,而仅仅是字符串:

                var items = await firebase
                        .Child("babysitter")
                        .OnceAsync<BabySitter>();
                list_babySitters.Clear();
                babysitterAdapter = null;
                foreach (var item in items)
                {
                    BabySitter account = new BabySitter();
                    account.id = item.Key;
                    account.name = item.Object.name;
                    account.age = item.Object.age;
                    account.phone = item.Object.phone;
                    account.city = item.Object.city;
                    account.address = item.Object.address;
                    account.email = item.Object.email;
                    account.eircode = item.Object.eircode;
                    account.availability = item.Object.availability;
                    list_babySitters.Add(account);

                }

自从我开始在Firebase中存储数组以来,我无法运行应用程序而不会在代码中此时崩溃:

var items = await firebase
.Child("babysitter")
.OnceAsync<BabySitter>();

我尝试了这些论坛,但使用Xamarin Android Visual Studio 2017找不到任何具有类似问题和解决方案的人。 谢谢您的任何建议帮助。

0 个答案:

没有答案