获取 Cloud Firestore 中 Map 字段的值

Get the value of a map field in cloud firestore

我有一个代码可以获取名为 Address 的地图的值。

Map<String, Object> map = document.getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
    if (entry.getKey().equals("Address")) {
        Log.i(TAG, entry.getValue().toString());
    }
}

这是输出 {街道=VP Inting Avenue, HouseNo=0186, Town=Tagbilaran City, Barangay=Poblacion I}

但我只想获取值 (0186 VP Inting Avenue Poblacion I Tagbilaran City),不包括它们的键。

我想你正在寻找:

Log.i(TAG, document.get("Address.HouseNo") + document.get("Address.Street") +
           document.get("Address.Barangay") + document.get("Address.Town"));

如果您知道字段的确切路径,则无需遍历所有字段。使用 . 您可以处理嵌套字段。