{ "random_key 1" : { "id": 0, "text": "This is text" }, "random_key 2" : { "id": 1, "text": "This is text" }} 如果我像这样存储我的数据,并且我想获得id等于0的节点.我该怎么做? 以上是问题的孩子,这是root的孩
{ "random_key 1" : { "id": 0, "text": "This is text" }, "random_key 2" : { "id": 1, "text": "This is text" } }
如果我像这样存储我的数据,并且我想获得id等于0的节点.我该怎么做?
以上是问题的孩子,这是root的孩子.
在您的情况下,您必须设置如下查询:DatabaseReference reference = FirebaseDatabase.getInstance().getReference(); Query query = reference.child("issue").orderByChild("id").equalTo(0); query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { // dataSnapshot is the "issue" node with all children with id 0 for (DataSnapshot issue : dataSnapshot.getChildren()) { // do something with the individual "issues" } } } @Override public void onCancelled(DatabaseError databaseError) { } });