我可以使用多个子项将数据插入我的firebase数据库吗?我可以像json示例那样有2个孩子的电话
{
"person1": {
"id": 12345,
"name": "John Doe",
"phones": {
"home": "800-123-4567",
"mobile": "877-123-1234"
}
}
}
答案 0 :(得分:0)
mDatabase.child("person1").child("phones").child("home").setValue("800-123-4567");
mDatabase.child("person1").child("phones").child("mobile").setValue("877-123-1234");
答案 1 :(得分:-2)
public void PostMultipleRecordsFireBase() {
int id=0;
String d1 = name.getText().toString();
String d2 = email.getText().toString();
String d3 = password.getText().toString();
Users users = new Users(d1, d2, d3, d4);
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference node = db.getReference("Users");
node.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
id = (int) snapshot.getChildrenCount();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
node.child(String.valueOf(id+1)).setValue(users);
name.setText("");
email.setText("");
password.setText("");
Toast.makeText(SignUp.this, "click", Toast.LENGTH_SHORT).show();
}