0
如何獲得使用迭代此JSON結構的關鍵在火力地堡的關鍵? 邏輯是,如果用戶是哈利·安德森,我想要搜索person0價值高達person6,如果該值被發現我想要得到它的關鍵在這種情況下是-KaSeO5n2xCl2sEnDpSi。我不知道這是否會使用迭代器來實現,但是如果有其他方法可以做到這一點,請確實建議。謝謝。
如何獲得使用迭代此JSON結構的關鍵在火力地堡的關鍵? 邏輯是,如果用戶是哈利·安德森,我想要搜索person0價值高達person6,如果該值被發現我想要得到它的關鍵在這種情況下是-KaSeO5n2xCl2sEnDpSi。我不知道這是否會使用迭代器來實現,但是如果有其他方法可以做到這一點,請確實建議。謝謝。
您可以嘗試
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference chatRef = database.getReference("chat").child("chat-participants");
chatRef.addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//do stuff iteration
}});
我不認爲這是做
ref.child("chat/chat-participants").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ArrayList<String> keyList = new ArrayList<>();
for (DataSnapshot child : dataSnapshot.getChildren()) {
Log.e("[email protected]@_Key::>", child.getKey());
keyList.add(child.getKey());
}
// your all keys are store in KeyList ArrayList
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.e("[email protected]@@_ERROR_>>", "onCancelled", firebaseError.toException());
}
});
參考鏈接顯式方法: - http://stackoverflow.com/questions/37094631/ get-the-pushing-id-for-specific-value-in-firebase-android http://stackoverflow.com/questions/38232140/how-to-get-the-key-from-the-value-in-firebase – Nainal
感謝您的回覆,但我無法通過鏈接找到答案。 @Nainal –