【发布时间】:2019-10-04 16:05:49
【问题描述】:
我想通过 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 call For 循环中写下这一行 Rootref= FirebaseDatabase.getInstance().getReference(); Rootref.child("Users").child("name").setValue(name);
但我在 firebase 中只获得了一条记录,而不是全部
任何帮助将不胜感激
【问题讨论】:
-
有什么问题?
-
Rootref= FirebaseDatabase.getInstance().getReference(); Rootref.child("Users").child("name").setValue(name);这个说法对吗?因为我在 firebase 中只获得了一条记录。
-
name是什么,也将您的 Firebase 规则更改为 true -
已经这样做了。 name 指 api 响应中的 full_name 字段
-
制作如下内容: Rootref.child("Users").child(user.getName()).setValue(name);如果您在 child.("name") 上设置值,您将每次都覆盖此值。 “名称”应该是唯一的。
标签: java android json firebase firebase-realtime-database