gpt4 book ai didi

java - 解包数据 firestore 查询返回的数组类型

转载 作者:行者123 更新时间:2023-11-30 10:15:09 24 4
gpt4 key购买 nike

这会返回一个 ArrayList,其中包含我存储在 Firestore 中的图像 Uris。我如何解包数组列表并一个一个地提取它们?下面是 logcat 的示例输出。

{0= https://firebasestorage.googleapis.com/v0/b/app ........., 1= https://firebasestorage.googleapis.com/v0/b/app ........., 2= https://firebasestorage.googleapis.com/v0/b/app

    firebaseFirestore.collection("Ads").whereEqualTo("user_id",user_id).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<String, Object> map = document.getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
ArrayList<String> imgUri = (ArrayList<String>) entry.getValue();
for (String uri : imgUri) {
Log.d(TAG, uri);
}
}
}
}
}

db structure

最佳答案

要解决这个问题,请使用以下代码行:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
rootRef.collection("Ads").whereEqualTo("user_id", user_id).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<String, Object> map = (Map<String, Object>) document.get("imgUri");
for (Map.Entry<String, Object> entry : map.entrySet()) {
Log.d(TAG, entry.getValue().toString());
}
}
}
}
});

输出将是:

https://firebasestorage.googleapis.com/v0/b/app.........,
https://firebasestorage.googleapis.com/v0/b/app.........,
https://firebasestorage.googleapis.com/v0/b/app.........,

关于java - 解包数据 firestore 查询返回的数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50595781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com