我的数据结构如下:
Database
Data1 {
Family: "Adam, John, Smith, Bob, Alice"
Age: "12, 23, 6, 5, 8"
Area: "GT6, GT9, GT12"
}
Data2 {
Family: "Tom, Ben, Berry, Hosh, Nico"
Age: "68, 43, 26, 15, 18"
Area: "67D, HG6, DHJD, 453"
}
Data3 {
Family: "Alice, Karan, faser, jenny, kietty"
Age: "14, 10, 15, 17, 5"
Area: "HG6, 67D, DHJD"
}
我只想打印/检索包含区域“67D”的数据,在此我想打印数据 2 和 3 中的所有数据。
如果我的问题不清楚,请告诉我。
我试过了
Query queryRef = ref.orderByChild("Area").equalTo("67D");
queryRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChild) {
System.out.println(snapshot.getKey());
}
// ....
});
最佳答案
根据 this SO answer加藤和 this Firebase blog post ,无法通过子字符串匹配进行过滤。
考虑让 child 使用区域作为键,然后您的查询将起作用:
ref.orderByChild("Area").equalTo("67D");
关于android - 如何从 Firebase 接收具有特定字符串 android 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42002796/