Правильный формат для использования базы данных: устанавливается с помощью firebase-tools

Итак, из всего, что я прочитал, с инструментами firebase, установленными глобально, моя командная строка 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

И получил ту же ошибку. Я в тупике, если формат загруженных данных не может быть загружен, какой формат мне может понадобиться?


person Mike Hanson    schedule 20.05.2017    source источник
comment
Это не очень помогает, но я поделюсь, что мне удалось скопировать ваши данные JSON и успешно загрузить их с помощью опубликованной вами команды. Я использовал firebase-tools версию 3.9.0 (firebase -V) в системе Windows.   -  person Bob Snyder    schedule 20.05.2017
comment
Спасибо за попытку Боба. Я запустил firebase -V и получил 3.9.0, должно быть, что-то странное в файле   -  person Mike Hanson    schedule 20.05.2017
comment
Да, я предполагаю, что это как-то связано с набором символов или каким-либо другим невидимым свойством файла, хотя странно, что загруженный файл также не удался.   -  person Bob Snyder    schedule 20.05.2017


Ответы (1)


Я решил проблему и, как намекнул Боб Снайдер, проблема заключалась в кодировке файла.

Первоначально я создал файл из шаблона файла JSON в Visual Studio 2017. Чтобы проверить кодировку, я открыл его в NotePad ++, и он показал кодировку как UTF-8-BOM. Я изменил кодировку на UTF-8 в NP ++ и выполнил исходную команду:

firebase database:set / database.json

Это сработало в первый раз, и моя база данных была перезаписана.

Поэтому для всех, кто сталкивается с этой проблемой, убедитесь, что кодировка вашего файла JSON - UTF-8.

person Mike Hanson    schedule 21.05.2017