gpt4 book ai didi

java - 将来自 Api 响应的数据添加到 Android 中的 Firebase 数据库中

转载 作者:行者123 更新时间:2023-12-02 01:30:21 25 4
gpt4 key购买 nike

我想通过 Android 中的 Volley API 响应将数据添加到 firebase 数据库。

"data": [{
"id": 1,
"full_name": "abc",
"email": "abc999@gmail.com",
"country_code": "+91",
"phone": 2147483647,
"profile_pic": "",
"type": 0,
"status": 1,
"reset_token": "",
"verify_token": "$2y$10$YXCZ1yteimLatQnAszJTi.HOGDZrr9xjKJtIDNs3uagX3elFUlC.2",
"created_at": "2019-05-07 07:53:29",
"updated_at": "2019-05-08 12:57:45",
"deleted_at": null
}, {
"id": 2,
"full_name": "xyz",
"email": "xyz@gm.com",
"country_code": "+91",
"phone": 2147483647,
"profile_pic": "",
"type": 0,
"status": 1,
"reset_token": null,
"verify_token": "$2y$10$Dtk.BdqBgHFyGcpj9bHyI.JRPJlc90Qmhxx0Imm0Mzzd3x6QchDMi",
"created_at": "2019-05-07 08:34:39",
"updated_at": "2019-05-07 08:34:39",
"deleted_at": null
}, {
"id": 3,
"full_name": "abc",
"email": "abc@gmail.com",
"country_code": "091",
"phone": 123456,
"profile_pic": "",
"type": 0,
"status": 1,
"reset_token": "$2y$10$mT9MqON6gMre0rKtoK0ON.VApZYBZP0PY55uM017Cz74E69qBILjm",
"verify_token": "$2y$10$HMBteSyYTKZ3XgYviUdNORKOw1Bpan5m0UcqIyx3dZrYUsNajou",
"created_at": "2019-05-07 08:47:29",
"updated_at": "2019-05-17 05:55:00",
"deleted_at": null
}

]

现在我希望 Firebase 数据应该如下所示

firebasedemo
.
+ Users
.
. . name:"abc"

我正在 Api 调用 For 循环中编写这一行 Rootref= FirebaseDatabase.getInstance().getReference(); Rootref.child("用户").child("名称").setValue(名称);

但我在 firebase 中只得到一条记录,而不是全部

任何帮助将不胜感激

最佳答案

尝试以下操作:

DatabaseReference rootref = FirebaseDatabase.getInstance().getReference(); 
rootref.child("Users").push().setValue(name);

来自docs :

public DatabaseReference push ()

Create a reference to an auto-generated child location. The child key is generated client-side and incorporates an estimate of the server's time for sorting purposes. Locations generated on a single client will be sorted in the order that they are created, and will be sorted approximately in order across all clients.

关于java - 将来自 Api 响应的数据添加到 Android 中的 Firebase 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184459/

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