这是我在Firebase数据库中的JSON数据结构:
familylist
|- 0
|--children
| |-- 0:"FGH"
| |-- 1:"HJU"
|-- code: "2222"
|-- family: "SWE"
|-- fatherName: "ABC"
|-- motherName: "XYZ"
|- 1
|--children
| |-- 0:"XXX"
| |-- 1:"YYY"
|-- code: "3333"
|-- family: "ABC"
|-- fatherName: "ERT"
|-- motherName: "XTS"
我从firebase-database检索Children
数据的代码:
DatabaseReference childrenKeyReference = FirebaseDatabase.getInstance().getReference().child("familylist").child("children").child(key);
Log.d(TAG, "children: " + childrenKeyReference);
childrenKeyReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String child = (String) dataSnapshot.getValue();
Log.d(TAG, "Child : " + child);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
这是LogCat的详细信息。显示空值。我无法弄清楚出了什么问题。请纠正我。
05-22 21:25:29.771 24743-24743/D/tag: children: https://bcm.firebaseio.com/familylist/children/0
05-22 21:25:29.774 24743-24743/D/tag: children: https://bcm.firebaseio.com/familylist/children/1
05-22 21:25:29.780 24743-24743/D/tag: Child : null
05-22 21:25:29.805 24743-24743/D/tag: Child : null
更新
正确设置订单后的新结果。我得到了这个:
05-22 20:52:36.091 8572-8572/D/tag: children: https://bcm.firebaseio.com/familylist/0/children/0
05-22 20:52:36.097 8572-8572/D/tag: children: https://bcm.firebaseio.com/familylist/1/children/1
05-22 20:52:36.136 8572-8572/D/tag: Child : FGH
05-22 20:52:36.137 8572-8572/D/tag: Child : YYY
答案 0 :(得分:2)
您可能偶然切换了节点访问顺序;)
您目前正在执行此操作:
...child("familylist").child("children").child(key);
但也许你应该这样做:
...child("familylist").child(key).child("children");
因为根据您的数据模型, familylist 显然没有子子节点。