我如何阅读Firebase中的所有类别和子类别?

时间:2016-07-18 14:17:13

标签: android json collections firebase firebase-realtime-database

我的应用程序中有很多类别和子类别,所以我从firebase中检索了日期。之后,我尝试将此数据转换为列表的集合以放入我的GUI。 这是我的类别中的示例: 你可以看到我有书类,
0 - >属性此类别和1 - >是子类别
我很困惑如何阅读这些类别和子类别,并将每个类别和子类别放在一个列表中,我可以在那之后轻松使用:)。

my categories

Firebase ref =新Firebase(Constants.FIREBASE_URL);

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_default, null, false);
       ref.addValueEventListener(new ValueEventListener() {
           @Override
           public void onDataChange(DataSnapshot dataSnapshot) {
               Map<String, Object> td = (HashMap<String,Object>) dataSnapshot.getValue();

                for (Map.Entry<String, Object> entry : categoriesMap.entrySet()) {
               System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
           }
           }

           @Override
           public void onCancelled(FirebaseError firebaseError) {

           }
       });

}

该代码的输出如下:

Key = books,
   Value = [{name=books}, {cookbooks={name=CookBooks}, fiction={name=Fiction},
   accessories=[{name=Accessories}, {bookcovers={name=BookCovers},  otherbookaccessories={name=OtherBookAccessories}, bookmarks={name=BookMarks}, 
   booklights={name=BookLights}}], nonfiction={name=Nonfiction}, otherbooks=
    {name=OtherBooks}, agazine={name=Magazine}, catalogues={name=Catalogues}, 
    childreanyoungadult={name=ChildreanYoungAdult}, audiobooks={name=AudioBooks}, 
    textbookseducation={name=TextBooksEducation}, antiquariancollectible=
    {name=AntiquarianCollectible}}]

0 个答案:

没有答案