Firebase. Database. DataSnapshot
ADataSnapshot instance contains data from aFirebaseDatabase location.
Summary
ADataSnapshot instance contains data from aFirebaseDatabase location. Any time you read
DataSnapshots are passed to events
, or
They are efficiently-generated immutable copies of the data at aFirebaseDatabase location. They can't be modified and will never change. To modify data at a location, use aDatabaseReference reference (e.g. with
).
Properties | |
|---|---|
Children | IEnumerable<DataSnapshot >Gives access to all of the immediate children of this Snapshot. |
ChildrenCount | longThe number of immediate children in the this snapshot. |
Exists | boolReturns true if the snapshot contains a non-null value. |
HasChildren | boolIndicates whether this snapshot has any children |
Key | stringThe key name for the source location of this snapshot. |
Priority | objectReturns the priority of the data contained in this snapshot as a native type. |
Reference | Used to obtain a reference to the source location for this Snapshot. |
Value | objectValue returns the data contained in this snapshot as native types. |
Public functions | |
|---|---|
Child(string path) | Get aDataSnapshot for the location at the specified relative path. |
GetRawJsonValue() | stringGetRawJsonValue() returns the data contained in this snapshot as a json serialized string. |
GetValue(bool useExportFormat) | objectGetValue() returns the data contained in this snapshot as native types. |
HasChild(string path) | boolCan be used to determine if thisDataSnapshot has data at a particular location |
ToString() | override stringA string representing theDataSnapshot as a key, value pair. |
Properties
Children
IEnumerable<DataSnapshot>Children
Gives access to all of the immediate children of this Snapshot.
Gives access to all of the immediate children of this Snapshot. Can be used in native for loops:
| Details | |
|---|---|
| Returns | The immediate children of this snapshot |
ChildrenCount
longChildrenCount
The number of immediate children in the this snapshot.
Exists
boolExists
Returns true if the snapshot contains a non-null value.
| Details | |
|---|---|
| Returns | True if the snapshot contains a non-null value, otherwise false |
HasChildren
boolHasChildren
Indicates whether this snapshot has any children
| Details | |
|---|---|
| Returns | True if the snapshot has any children, otherwise false |
Key
stringKey
The key name for the source location of this snapshot.
Priority
objectPriority
Returns the priority of the data contained in this snapshot as a native type.
Returns the priority of the data contained in this snapshot as a native type. Possible return types:
- double
- string Note that null is also allowed.
| Details | |
|---|---|
| Returns | the priority of the data contained in this snapshot as a native type |
Reference
DatabaseReferenceReference
Used to obtain a reference to the source location for this Snapshot.
| Details | |
|---|---|
| Returns | ADatabaseReference corresponding to the location that this snapshot came from |
Value
objectValue
Value returns the data contained in this snapshot as native types.
Value returns the data contained in this snapshot as native types. The possible types returned are:
- bool
- string
- long
- double
- IDictionary{string, object}
- List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON.
| Details | |
|---|---|
| Returns | The data contained in this snapshot as native types |
Public functions
Child
DataSnapshotChild(stringpath)
Get aDataSnapshot for the location at the specified relative path.
Get aDataSnapshot for the location at the specified relative path. The relative path can either be a simple child key (e.g. 'fred') or a deeper slash-separated path (e.g. 'fred/name/first'). If the child location has no data, an emptyDataSnapshot is returned.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | TheDataSnapshot for the child location |
GetRawJsonValue
stringGetRawJsonValue()
GetRawJsonValue() returns the data contained in this snapshot as a json serialized string.
GetRawJsonValue() returns the data contained in this snapshot as a json string.
| Details | |
|---|---|
| Returns | The data contained in this snapshot as json. Return null if no data. |
GetValue
objectGetValue(booluseExportFormat)
GetValue() returns the data contained in this snapshot as native types.
GetValue() returns the data contained in this snapshot as native types. The possible types returned are:
- bool
- string
- long
- double
- IDictionary{string, object}
- List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON. If useExportFormat is set to true, priority information will be included in the output. Priority information shows up as a .priority key in a map. For data that would not otherwise be a map, the map will also include a .value key with the data.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | The data, along with its priority, in native types |
HasChild
boolHasChild(stringpath)
Can be used to determine if thisDataSnapshot has data at a particular location
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | Whether or not the specified child location has data |
ToString
overridestringToString()
A string representing theDataSnapshot as a key, value pair.
It returns the following form:DataSnapshot { key = {Key}, value = {Value} };
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-06-17 UTC.