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

问题描述

我正在查看的文档,并指出
$ b

但是,发现似乎总是将值设置为true,无论它是否是一个JSON基元或对象?



例如从我读过的东西我期望下面的调用



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

  {
text:Ahoy!,
user_id :jack
}

取而代之的是

  {
text:true,
user_id:true
}


$ b我明白在这个例子中我提供的浅度并不是必须的,因为它是最低级别的,但是我发现这个问题也是我自己的数据在更高的水平是一切正在返回true。



有没有办法重新使用浅参数来建立JSON基元的值?

解决方案

当您使用<$ c查询Firebase REST API $ c> shallow = true ,无论数据的类型如何,它都会返回 true 在它下面。没有办法改变这种行为。



有关原始值的文档适用于更深入地查询一个层次。你的情况,如果你运行这个查询:,你会得到嗨!



$ <$> $ $ $ > 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

    code $ pre $ b $ li $ p $ lt; p $ lt; code> https:// samplechat。 / b
    $ b

      喂! 



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

    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 to return

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

    instead it is returning

    {
        "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.

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

    解决方案

    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.

    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!"

    So:

    • 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使用浅数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    05-27 03:40
    查看更多