我需要从 Firestore Firebase 获取数据,我需要从“雇主”集合 -> “TH17...”文档中获取字段“公司”的值。我尝试了一些方法,但没有用。
我该怎么做?
我试试这个:
docref = db.collection("employer").document("TH17...");
docref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
}
}
}
});
最佳答案
I need to get the value of field "company" from "employer" collection -> "TH17..." document.
要解决这个问题,请更改以下代码行:
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
到
String company = document.getString("Company");
Log.d("TAG", "Company: " + company);
您的 logcat 中的结果将是:
Company: Test
关于java - 从 Cloud Firestore 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53230921/