对于每个循环,在entry.getValue()内部,还有另一个来自firestore的 map 。我怎样才能得到?
代码:
@Override
public void onComplete (@NonNull Task < QuerySnapshot > task) {
if (task.isSuccessful()) {
// binding.contentMain.noData.setVisibility(View.GONE);
for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
showLog("Data: " + document.getData());
postMap.putAll(document.getData());
}
try {
for (Map.Entry<String, Object> entry : postMap.entrySet()) {
if (entry.getKey().equals(CONTENT)) {
showLog("value: " + entry.getValue().toString());
contentMap = new HashMap<>();
contentMap.putAll(entry.getValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
// binding.contentMain.noData.setVisibility(View.VISIBLE);
showLog("Error getting documents: " + task.getException());
}
}
我尝试了如下但编译器错误。无建议:
Map map = new HashMap();
((Map)map.get( "keyname" )).get( "nestedkeyname" );
最佳答案
试试这个
contentMap.putAll((Map<? extends String, ? extends Object>) entry.getValue());
关于java - 如何从entry.getValue 获取另一个HasMap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62377012/