Firebase REST API 处理浅层数据 [英] Firebase REST API working with shallow data

查看:44
本文介绍了Firebase REST API 处理浅层数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 Firebase REST API 的文档,它指出

I am looking at the documentation for the Firebase REST API and it states that

Shallow - 这是一项高级功能,旨在帮助您处理大型数据集而无需下载所有内容.将此设置为 true 以限制在某个位置返回的数据的深度.如果该位置的数据是 JSON 原语(字符串、数字或布尔值),则将简单地返回其值.如果该位置的数据快照是 JSON 对象,则每个键的值将被截断为 true.

Shallow - This is an advanced feature, designed to help you work with large datasets without needing to download everything. Set this to true to limit the depth of the data returned at a location. If the data at the location is a JSON primitive (string, number or boolean), its value will simply be returned. If the data snapshot at the location is a JSON object, the values for each key will be truncated to true.

但是,从我发现的情况来看,无论它是 JSON 原语还是对象,它似乎总是将该值设置为 true?

However from what I have found it seems to always set the value to true regardless of whether it is a JSON primitive or object?

例如,根据我所读到的内容,我希望收到以下调用

eg from what I have read I would expect the below call

https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/.json?print=pretty&shallow=true 返回

{
    "text" : "Ahoy!",
    "user_id" : "jack"
}

相反,它正在返回

{
    "text" : true,
    "user_id" : true
}

我知道在这个例子中我提供了不需要的浅层,因为它是最低级别,但是我发现这个问题也存在于我自己的更高级别的数据中,一切都恢复正常.

I understand in this example I provided shallow isn't required as it is the lowest level, however I have found this issue also with my own data at higher levels were everything is returning true.

有没有办法按照使用浅层参数的建议返回 JSON 原语的值?

Is there a way to return the value of a JSON primitive as suggested using the shallow param?

推荐答案

当您使用 shallow=true 查询 Firebase REST API 时,它会为任何键返回 true存在于您查询的级别上,无论其下的数据类型如何.没有办法改变这种行为.

When you query the Firebase REST API with shallow=true, it will return true for any key that exists on the level that you query, regardless of the type of the data underneath it. There is no way to change that behavior.

当您查询更深一层时,有关原始值的文档适用.在您的情况下,如果您运行此查询:https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/text.json?print=pretty&shallow=true,你回来Ahoy!"

The documentation about primitive values applies when you query one level deeper. In your case, if you run this query: https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/text.json?print=pretty&shallow=true, you get back "Ahoy!"

所以:

  • https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/.json?print=pretty

{
  "text" : "Ahoy!",
  "user_id" : "jack"
}

  • https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/.json?print=pretty&shallow=true

    {
      "text" : true,
      "user_id" : true
    }
    

  • https://samplechat.firebaseio-demo.com/message_list/-K6ojd3dJQ3AVi36cruT/text.json?print=pretty&shallow=true

    "Ahoy!"
    

  • 这篇关于Firebase REST API 处理浅层数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆