gpt4 book ai didi

android - 在 firebase android 中追加数据

转载 作者:太空狗 更新时间:2023-10-29 16:14:15 25 4
gpt4 key购买 nike

我想在 firebase 中附加一些数据,但它被替换了。

我开始于:

scorching-fire-2211  
Latlng: "7.00003"
REGISTER_NO: "13MSE0149"

现在当我尝试添加新的 REGISTER_NO

Firebase.setAndroidContext(this);
Firebase myFirebaseRef = new Firebase("https://scorching-fire-2211.firebaseio.com/");
myFirebaseRef.child("REGISTER_NO").setValue("13mse0254");

数据变为:

scorching-fire-2211  
Latlng: "7.00003"
REGISTER_NO: "13mse0254"

旧的正在被替换,但我希望将这个附加到那个。

最佳答案

您需要使用 .push()REGISTER_NO 创建一个列表。

Firebase myFirebaseRef = new Firebase("https://scorching-fire-2211.firebaseio.com/");
myFirebaseRef.child("REGISTER_NO").push().setValue("13mse0254");

这将维护一个 JSON 格式的列表,如下所示:

{
"REISTER_NO": {
"-K6Zjr34pzqjvO9ffwrI": "13mse0254"
}
}

这个看起来很奇怪的字符串是由 Firebase SDK 创建的推送 ID。如果你想要自己的 key ,你可以指定 .child() key :

Firebase myFirebaseRef = new Firebase("https://scorching-fire-2211.firebaseio.com/");
myFirebaseRef.child("REGISTER_NO").child("13mse0254").setValue(true);

这将创建一个结构:

{
"REGISTER_NO": {
"13mse0254": true
}
}

然后您可以通过前往/REGISTER_NO/13mse0254 的路径来检索它。

关于android - 在 firebase android 中追加数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34483415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com