简体   繁体   English

从 firebase 检索到的数据中删除大括号和等号

[英]Remove curly braces and equal sign from data retrieved from firebase

So, I am using android studio to make an app that displays data stored in firebase real-time database.所以,我正在使用 android 工作室制作一个应用程序,显示存储在 firebase 实时数据库中的数据。 The app is simple, it displays the name and phone number from firebase to the app.该应用程序很简单,它将姓名和电话号码从 firebase 显示到应用程序。

The app works fine and even displays the data but the only thing is it displays the data/values with curly braces and an equal sign (like a JSON format) is there anyway I can make it display just the desired values and not the extra signs and punctuation该应用程序运行良好,甚至可以显示数据,但唯一的问题是它用大括号和等号(如 JSON 格式)显示数据/值,无论如何我可以让它只显示所需的值而不是额外的符号和标点符号

附有问题的应用程序屏幕图像

Code:代码:

ArrayList<String> list =new ArrayList<>();
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.list_view, list);
listView.setAdapter(adapter);

DatabaseReference ref= FirebaseDatabase.getInstance().getReference().child("Car Wash");

ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        list.clear();
        for(DataSnapshot snapshot: dataSnapshot.getChildren()){
            list.add(snapshot.getValue().toString());
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
});

What you're seeing is the toString() output of the value a Firebase DataSnapshot that represents an object with multiple values.您看到的是值 a Firebase DataSnapshottoString() output,表示具有多个值的 object。

You'll want to get the individual values from that snapshot, and display their values with something like this:您需要从该快照中获取各个值,并使用如下所示显示它们的值:

String name = snapshot.child("Name").getValue(String.class);
String phoneNr = snapshot.child("Phone Number").getValue(String.class);
list.add(name+" ("+phoneNr+")");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 firebase v9 检索到的数据未定义 - Retrieved data from firebase v9 is undefined RecyclerView 正在循环从 firebase 检索到的相同数据 - RecyclerView is looping the same data retrieved from firebase firebase 模拟器数据未保存并从某些缓存中检索 - firebase emulator data not saved and retrieved from some cache 如何获取从 Dart Flutter Firebase 检索到的数据的值? - How to get value of data retrieved from Dart Flutter Firebase? Firebase 更新检索到的数据 - Firebase updating the retrieved data 如何在包含从 firebase 数据库 JavaScript 检索到的数据的数组上执行 forEach 循环 - How do you do a forEach loop on an array containing data retrieved from firebase database JavaScript 更改从 Firebase PopulateView 检索到的 RecyclerView 中项目的排列顺序 - Change the Arrangement order of items in RecyclerView Retrieved From Firebase PopulateView 没有检索到特定集合的数据 Firebase - No data retrieved for specific collection Firebase 自定义 Object 检索自 Firebase 始终具有 Null 属性 - Custom Object Retrieved from Firebase Always Has Null Attributes Firebase Auth - 没有来自谷歌登录提供商的电子邮件 - Firebase Auth - no email from google sign in provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM