我不知道如何处理 Firebase get 查询返回的对象

I can't figure out how to work with the object returned by Firebase get query

我正在使用 Expo 构建 React Native 应用程序并集成 Firebase(实时数据库),我知道它有一些限制 (https://docs.expo.dev/guides/using-firebase/)。我正在尝试使用 await get(query(... 获取数据快照并已成功完成,但我无法弄清楚我正在使用什么。当我 console.log 我得到这个:

Object {
  "key1": value1,
  "key2": value2,
}

我试图 return 使用 Object.keys() 的键数组,但它 return 是这样的:

Array [
  "_node",
  "ref",
  "_index",
]

这与我在互联网上看到的 Object.keys() 示例不一致,这让我觉得这不是我认为的 JSON 对象。我试过用其他一些东西四处寻找,但无法弄清楚。问题是,当我在对象上使用 typeof 时,它只是 returns 'object' 这对我来说有点太模糊了 google 机器。

以下是我的代码的表示。感谢您的帮助。

import { initializeApp } from 'firebase/app';
import { get, getDatabase, query, ref } from 'firebase/database';

const firebaseConfig = {
    databaseURL: '<myURL>',
    projectId: '<myID>',
};
const app = initializeApp(firebaseConfig);

export default async function myFunction() {
    const db = getDatabase(app);
    const readReference = ref(db, '/<I am only reading a piece of the data>')
    const existingData = await get(query(readReference))
    const dataKeys = Object.keys(existingData)
    console.log(dataKeys)
    console.log(existingData)
    console.log(typeof existingData)
}

您从 Firebase 返回的内容被称为 DataSnapshot,其中包含您阅读的位置的 JSON,以及一些更多的元数据。

如果您只想获取快照的 JSON 值,请使用 snapshot.val(),如 Storing Data and Receiving Updates 的 Expo 文档中所示。

类似于:

const existingData = await get(query(readReference))
const dataKeys = Object.keys(existingData.val())
console.log(dataKeys)
console.log(existingData.val())
console.log(typeof existingData.val())