Parsing the DataSnapshot object

In a simple way, DataSnapshot can be accessed through the getValue method. We can use the child() method to reach to a specific path of a snapshot. Consider the following example code snippet that fetches the title:

String title = mDataSnapshot.child("message1").child("title").getValue(String.class);

And all the children can be accessed using the getChildren() method. Consider the following code that is reading all the child details inside a for each loop:

for (DataSnapshot child : mDataSnapshot.getChildren()) {
Log.i(TAG, child.getKey());
Log.i(TAG, child.getValue(String.class));
}