如何在Firebase中的android应用中创建一个空表? [英] How can I create an empty table from android app in Firebase?

查看:96
本文介绍了如何在Firebase中的android应用中创建一个空表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android平台上开发实时应用程序,我想首先在Firebase数据库中添加具有特定名称且没有任何信息的表.有可能吗,我该怎么办?

I'm developing real-time application on Android platform and I want to add a table with specific name and no information at first in Firebase database. Is it possible and how can I do it?

推荐答案

Firebase没有表"的概念,并且没有表名"

Firebase doesn't have the notion of 'tables' and there are no 'table names'

摘自Firebase入门指南

From the getting started guide from Firebase

所有Firebase数据库数据都存储为JSON对象.没有表格或记录.

因此,在开发应用程序时,了解NoSQL(JSON)数据库和SQL之间的区别很重要.

So when developing your app it's important to understand the difference between NoSQL (JSON) databases and SQL.

此外,您在Firebase中实际上无法拥有一个没有数据的节点.

Additionally, you can't really have a node in Firebase with no data.

因此,您可能需要重新考虑为什么需要一个没有信息的节点;一旦您写入信息,就会创建父节点.

So, you may want to re-think why you need a node with no information; as soon as you write information, the parent node will be created.

例如

定义用户

public User(String name, String favFood) {
        this.name = name;
        this.favFood = favFood;
    }

写一些数据

Firebase userToAddRef = ref.child("users").child("user_0");
User aUser = new User("Harry Nilsson", "Lime Coconut");
userToAddRef(aUser);

这将创建父用户"节点,并添加一个子节点"user_0",其中包含一个子哈里·尼尔森"和他最喜欢的食物.

This will create the parent 'users' node and add a child node 'user_0' that contains a single child 'Harry Nilsson' and his favorite food.

{
  "users": {
    "user_0": {
      "name": "Harry Nilsson",
      "favFood": "Lime Coconut"
    }
  }
}

如果您确实需要一个没有数据的节点,那么也许作为占位符(?)是写节点,以便最终JSON结构为

If you really NEED to have a node with no data, maybe as a placeholder (?) is to write the node so the end JSON structure would be

{
  someNodeName: true
}

这篇关于如何在Firebase中的android应用中创建一个空表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆