您应该getKey()
在检索到的方法中调用该方法dataSnapshot
:
final Query userQuery = mRef.orderByChild("First Name"); userQuery.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { map.clear(); //Get the node from the datasnapshot String myParentNode = dataSnapshot.getKey(); for (DataSnapshot child: dataSnapshot.getChildren()) { String key = child.getKey().toString(); String value = child.getValue().toString(); map.put(key,value); }