如何在没有DataSnapshot的情况下从Firebase数据库检索数据? #AskFirebase [英] How to retrieve data from firebase database without DataSnapshot? #AskFirebase

查看:165
本文介绍了如何在没有DataSnapshot的情况下从Firebase数据库检索数据? #AskFirebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在firebase的数据库



我想获得等于200的页面的值。

当我尝试这样做时:

  DatabaseReference my = userid_database.child(Books)。child(Book 1)。child(Page); 

System.out.println(my);

输出:

  https://my-proje-book-timer.firebaseio.com/qpPLvgpM0TMF6vz4Kqw8QaYroG83/Books/Book%201/Page 

当我尝试这样做时:

  DatabaseReference my = userid_database.child(Books) .child(Book 1)。child(Page)。getKey(); 

System.out.println(my);

输出:

  Page 

我不想使用这个:



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ text = dataSnapshot.getValue(String.class);



$ b @Override
public void onCancelled(DatabaseError databaseError){

}
});

因为我想获取每个Book页面的所有值并使用这些值进行计算。这样,我无法获得方法外的值。 解决方案

如果你不想使用监听器,您可以使用 REST API 轻松地进行HTTP查询以查找你想要的数据,假设它没有认证是可读的。如果你需要认证,这将变得更加困难。



但是现在只要学习让听众能够为你工作,即使你不习惯以进行那种处理。

This my database in firebase

I want to get the value of page which is equal to 200.

When I tried like that:

DatabaseReference my= userid_database.child("Books").child("Book 1").child("Page");

    System.out.println(my);

Output:

https://my-proje-book-timer.firebaseio.com/qpPLvgpM0TMF6vz4Kqw8QaYroG83/Books/Book%201/Page

When I tried like that:

DatabaseReference my= userid_database.child("Books").child("Book 1").child("Page").getKey();

    System.out.println(my);

Output:

Page

I don't want to use this:

 my.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String text = dataSnapshot.getValue(String.class);


        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

Because I want to get all values for each Book pages and make a calculation with these values. In this way, I couldn't get the values outside of the method.

解决方案

If you don't want to use a listener, you can use the REST API to easily make an HTTP query to find the data you want, assuming that it's readable without authentication. If you need authentication, it gets more difficult.

But you're really better off just learning now to make the listeners work for you, even if you're not accustomed to that kind of processing.

这篇关于如何在没有DataSnapshot的情况下从Firebase数据库检索数据? #AskFirebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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