這是火力地堡數據庫我的JSON數據結構:如何檢索數據庫火力內部數組的數組數據:Android的
familylist
|- 0
|--children
| |-- 0:"AAA"
| |-- 1:"BBB"
|-- code: "2222"
|-- family: "SWE"
|-- fatherName: "ABC"
|-- motherName: "XYZ"
|- 1
|--children
| |-- 0:"XXX"
| |-- 1:"YYY"
|-- code: "3333"
|-- family: "ABC"
|-- fatherName: "ERT"
|-- motherName: "XTS"
我能夠從JSON樹拉起的所有領域,除了children
。任何人都可以告訴我如何從children
檢索數據?
這是我的代碼,用於檢索firebase數據庫中除兒童以外的所有字段。爲了檢索children
值,可以對此代碼執行什麼操作?我無法弄清楚。
familyListReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
String key = (String) ds.getKey();
Log.d(TAG, "Key" + key);
DatabaseReference keyReference = FirebaseDatabase.getInstance().getReference().child("familylist").child(key);
Log.d(TAG, "Key reference: " + keyReference);
keyReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String code = dataSnapshot.child("code").getValue(String.class);
String family = dataSnapshot.child("family").getValue(String.class);
String father = dataSnapshot.child("fatherName").getValue(String.class);
String mother = dataSnapshot.child("motherName").getValue(String.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "Read failed");
}
}); // [End of keyReference]
} // END of for Loop
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "Read failed");
}
}); // [End of familyListDatabaseReference]
完美無瑕!實際上,我已經將一個現有的JSON文件導入到firebase數據庫,然後從Activity中提取數據。 – Chip