【问题标题】:Correct format to use database:set with firebase-tools使用数据库的正确格式:使用 firebase-tools 设置
【发布时间】:2017-05-20 07:37:35
【问题描述】:

所以从我读过的所有内容来看,在全局安装 firebase-tools 后,我的 Windows 命令提示符在包含我的项目的文件夹中打开,一个工作的 firebase.json 文件(在该 firebase 部署中工作正常)我应该能够运行以下命令覆盖我的 firebase 数据库的全部内容:

firebase database:set / database.json

但是使用 database.json 我得到以下错误:

Error: HTTP Error: 400, Invalid data; couldn't parse JSON object, array, or value.

database.json 包含以下内容:

{
  "catalogue": {
    "csi": {
      "descriptionRoute": "csi",
      "fileName": "ctk%20Currency%20Strength%20Indicator.algo",
      "id": 1,
      "imageUrl": "/images/csi.png",
      "isFeatured": true,
      "name": "Currency Strength Indicator",
      "shortDescription": "Plots the relative strength of 8 major currencies as a line chart",
      "type": "indicator"
    },
    "csh": {
      "descriptionRoute": "csh",
      "fileName": "ctk%20Currency%20Strength%20Heatmap.algo",
      "id": 2,
      "imageUrl": "/images/csh.png",
      "isFeatured": true,
      "name": "Currency Strength Heatmap",
      "shortDescription": "Plots the relative strength of 8 major currencies as a heatmap",
      "type": "indicator"
    },
    "ffc": {
      "descriptionRoute": "ffc",
      "fileName": "ctk%20FF%20Calendar.algo",
      "id": 3,
      "imageUrl": "/images/ffc.png",
      "isFeatured": true,
      "name": "Forex Factory Calendar",
      "shortDescription": "Lists upcoming events from the Forex Factory RSS feed",
      "type": "indicator"
    },
    "atrsl": {
      "descriptionRoute": "atrsl",
      "fileName": "ctk%20ATR%20Stop%20Loss%20Indicator.algo",
      "id": 4,
      "imageUrl": "/images/atrsl.png",
      "isFeatured": false,
      "name": "ATR Stop Loss Indicator",
      "shortDescription": "Displays ATR and stop loss values based on your requirements.",
      "type": "indicator"
    },
    "ha": {
      "descriptionRoute": "ha",
      "fileName": "ctk%20Heken%20Ashi.algo",
      "id": 5,
      "imageUrl": "/images/ha.png",
      "isFeatured": false,
      "name": "Heiken Ashi",
      "shortDescription": "Paints Heiken Ashi candles on the host chart.",
      "type": "indicator"
    },
    "hama": {
      "descriptionRoute": "hama",
      "fileName": "ctk%20Heken%20Ashi%20Moving%20Average.algo",
      "id": 6,
      "imageUrl": "/images/hama.png",
      "isFeatured": false,
      "name": "Heiken Ashi Moving Average",
      "shortDescription": "Paints Heiken Ashi Moving Average on the host chart.",
      "type": "indicator"
    },
    "psl": {
      "descriptionRoute": "psl",
      "fileName": "ctk%20Psych%20Levels%20.algo",
      "id": 7,
      "imageUrl": "/images/psl.png",
      "isFeatured": false,
      "name": "Psych Levels",
      "shortDescription": "Draws lines at psychological levels that often form string Support and Resistance",
      "type": "indicator"
    }
  }
}

我看不出有什么问题,我在谷歌上搜索的所有内容都表明它很好,但我能得到的只是错误。

所以我跑了

firebase database:get / > database2.json

结果如下:

{
  "catalogue": [
    null,
    {
      "descriptionRoute": "csi",
      "fileName": "ctk%20Currency%20Strength%20Indicator.algo",
      "id": 1,
      "imageUrl": "/images/csi.png",
      "isFeatured": true,
      "name": "Currency Strength Indicator",
      "shortDescription": "Plots the relative strength of 8 major currencies as a line chart",
      "type": "indicator"
    },
    {
      "descriptionRoute": "csh",
      "fileName": "ctk%20Currency%20Strength%20Heatmap.algo",
      "id": 2,
      "imageUrl": "/images/csh.png",
      "isFeatured": true,
      "name": "Currency Strength Heatmap",
      "shortDescription": "Plots the relative strength of 8 major currencies as a heatmap",
      "type": "indicator"
    },
    {
      "descriptionRoute": "ffc",
      "fileName": "ctk%20FF%20Calendar.algo",
      "id": 3,
      "imageUrl": "/images/ffc.png",
      "isFeatured": true,
      "name": "Forex Factory Calendar",
      "shortDescription": "Lists upcoming events from the Forex Factory RSS feed",
      "type": "indicator"
    },
    {
      "descriptionRoute": "atrsl",
      "fileName": "ctk%20ATR%20Stop%20Loss%20Indicator.algo",
      "id": 4,
      "imageUrl": "/images/atrsl.png",
      "isFeatured": false,
      "name": "ATR Stop Loss Indicator",
      "shortDescription": "Displays ATR and stop loss values based on your requirements.",
      "type": "indicator"
    }
  ]
}

然后马上跑

firebase 数据库:set / database2.json

并得到同样的错误。我很困惑,如果下载的数据格式不能上传,我需要什么格式?

【问题讨论】:

  • 这没有多大帮助,但我将分享我能够复制您的 JSON 数据并使用您发布的命令成功上传它。我在 Windows 系统上使用了 firebase-tools 版本 3.9.0 (firebase -V)。
  • 感谢您试用 Bob。我运行了 firebase -V 并得到 3.9.0 的文件一定很奇怪
  • 是的,我猜这与文件的字符集或其他一些不可见的属性有关,尽管下载的文件也失败了很奇怪。

标签: firebase firebase-tools


【解决方案1】:

我解决了这个问题,正如 Bob Snyder 暗示的那样,问题在于文件的编码。

我最初从 Visual Studio 2017 中的 JSON 文件模板创建了该文件。为了检查编码,我在 NotePad++ 中打开它,它显示编码为 UTF-8-BOM。我在 NP++ 中将 Encoding 更改为 UTF-8 并运行原始命令:

firebase database:set / database.json

它第一次工作,我的数据库被覆盖了。

因此,对于遇到此问题的其他人,请确保您的 JSON 文件的编码是 UTF-8。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-15
    • 2022-01-08
    • 1970-01-01
    • 2011-01-28
    • 2020-03-14
    • 1970-01-01
    • 2018-07-13
    • 2016-03-24
    相关资源
    最近更新 更多