android - 将多个值保存到单个用户 - Firebase

标签 android json firebase firebase-realtime-database

我有以下需要使用 Firebase 构建的 JSON 结构。 如何在 Firebase 中保存以下 JSON 结构的数据。

"followers": {
    "user1": {
      "user2": true,
      "user3": true
    }
  }

下面是我的代码,但它总是用 user3 替换 user2

Map<String, String> data= new HashMap<String, String>();
data.put(uid,"true");
followersTable.child(user1.uid).setValue(data);

最佳答案

setValue 方法是破坏性的。这意味着它将用作为参数给出的新数据替换现有数据。

Use updateChildren instead.

Map<String, String> data= new HashMap<String, String>();
data.put(uid,"true");
followersTable.child(user1.uid).updateChildren(data);

关于android - 将多个值保存到单个用户 - Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36198152/

相关文章:

android - 无法删除 nav_host_fragment 顶部的空间

Android N 通知标题和图标颜色更深

json - Swift - 将 [[String :Any? ]] 转换为数据

android - 是否可以将 Realm 对象转换为 JSON 对象?

javascript - 使用 if 语句确定 Firebase 用户是否可以访问某些 React Router 路径

Firebase 存储安全规则 : After specifying "allow read: if request.auth != null" I can still access my files using the download link provided

android - 在没有互联网的设备上通过 Firebase 隐藏 ProgressDialog

Android RotateAnimation 完成

android - GoogleApiClient 未配置为使用此调用所需的 Fitness.API

java - 在Retrofit中使用Gson解析JSON