【问题标题】:Firebase - Invalid JSON data or key values. Key values can’t contain $ # [ ] / orFirebase - 无效的 JSON 数据或键值。键值不能包含 $ # [ ] / 或
【发布时间】:2016-12-04 17:47:21
【问题描述】:

我正在尝试将我的 JSON 文件导入我的 Firebase,但它一直给我这个错误。我不知道为什么不允许导入这个 JSON 文件,因为 JSONLint 说它是一个有效的 JSON 文件。

这是文件:

{
  "Featured" : {
      "artist" : "james turell",
      "artistEPK" : "artistsownepk.pdf",
      "author" : "john queue author",
      "date" : "7/28/2016",
      "fullScreenImg" : "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687",
      "linksToMedia" : [ "www.wallplay.com/project-name/james-t/press.html" ],
      "linksToPress" : [ "" ],
      "location" : "10 Main Street",
      "mainImg" : "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687",
      "pressImgs" : [ "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687" ],
      "pressRelease" : "projectpressrelease.pdf",
      "projectImgs" : [ "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687", "https://firebasestorage.googleapis.com/v0/b/wallplay-a8440.appspot.com/o/Screen%20Shot%202016-06-08%20at%2012.00.06%20PM.png?alt=media&token=1df5d60d-808c-48bb-a591-e005f82e4687" ],
      "projectSubheader" : "subheader of project",
      "projectTitle" : "title of project",
      "projectURL" : "",
      "soundFile" : [ ],
      "text" : "here there would be a text for james turell",
      "videoURL" : ""
    },
  "Future" : {

  },
  "Past" : {

  },
  "Present" : {

  }
}

使用网页界面导入 json 时出现问题

【问题讨论】:

标签: json firebase firebase-realtime-database


【解决方案1】:

您发布的 JSON 对 Firebase 有效,因此问题不在于此 JSON。它必须在您的应用程序中的其他位置。

【讨论】:

  • 我正在尝试通过按“导入 JSON”在 url 端导入它。但我觉得它有问题,因为如果我尝试导入最简单的 JSON,它会说它是无效的。所以我不知道它有什么问题。我必须为它创建一个全新的项目吗?
  • 第二次检查,我发现无论我有什么项目,我都无法上传。这是怎么回事?我正在使用 Google Chrome 和 Mozilla。两者都不起作用
  • 我也认为这是 firebase 的错误,对我来说,即使对于非常简单的 JSON 文件,导入也不起作用:{"a":1}
【解决方案2】:

我的文件名是“something-somethingelse”,即文件名中有一个“-”字符。将其更改为“something.json”解决了问题

所以,文件名中不要有任何特殊字符。

【讨论】:

    【解决方案3】:

    我只是在这方面花了一些时间,并在收到此错误消息时为我(可能还有其他许多人)发现了这个问题。看来firebase只能导入UTF-8编码的文件(无BOM)

    我觉得很奇怪,因为我无法重新导入刚刚导出的内容。

    我尝试了所有带有 LE 和 BE 的 UTF 版本 8、16,有和没有 BOM,只有 UTF-8 有效

    我希望 firebase 没有这个完全误导性的错误消息

    【讨论】:

      【解决方案4】:

      有两件事可以帮助别人节省几个小时的时间:

      1) 空字符串是有效的 JSON 键,它们不是有效的 Firebase 键。

      2) 虽然 Web 工具的错误消息很糟糕,但命令行工具实际上提供了有用的信息,例如行号(当您有 300K+ 行文件时很好)

      例如

      firebase --project 数据库:设置/import.json

      从根目录覆盖所有内容

      【讨论】:

      【解决方案5】:

      我对包含大量数据的 JSON 也有类似的问题。我通过使用firebase import tool 解决了这个问题。它具有导入到特定节点等的选项。

      【讨论】:

      【解决方案6】:

      这发生在我身上,原因完全不同:当数据添加到某些集合时,我的 Firebase 函数会触发。 GUI工具给了我OP得到的无用错误。但是使用 CLI 运行,我得到了:

      Error: HTTP Error: 400, This request would cause too many functions to be triggered.
      

      所以,这个错误最终真正挽救了我的隐藏,因为为我正在导入的数百个节点中的每一个运行一个函数将是灾难性的。

      为了解决这个问题,我部署了我的应用程序代码,其中的功能被注释掉了,然后能够使用 GUI 导入我的数据。输入数据后,我取消注释掉函数并再次部署。

      【讨论】:

      • 耶!我也必须这样做!谢谢。
      • 这是我在开发工具中检查网络调用时收到的消息。 UI 消息很模糊
      【解决方案7】:

      如果你创建了很多触发函数。您必须删除触发的功能。下次再试。这种方式适合我。

      【讨论】:

        【解决方案8】:

        我刚刚发现 Firebase 抛出此错误的另一个原因:

        这是 Firebase 拒绝上传的数据:

         {
                    "S. No.": 2,
                    "University Name": "Acharya Nagarjuna University, Guntur (Id: U-0003)",
                    "College Name": "Abhinav Institute of Management & Technology (Id: C-39450)",
                    "College Type": "Affiliated College",
                    "State Name": "Andhra Pradesh",
                    "District Name": "Prakasam"
                  } 
        

        我想过改变“S. No.”的键名。并且成功了。

        {
                    "S": 2,
                    "University Name": "Acharya Nagarjuna University, Guntur (Id: U-0003)",
                    "College Name": "Abhinav Institute of Management & Technology (Id: C-39450)",
                    "College Type": "Affiliated College",
                    "State Name": "Andhra Pradesh",
                    "District Name": "Prakasam"
                  } 
        

        Firebase 接受了后一种格式(我认为问题在于 .(dot) 后跟空格。) 我希望这会有所帮助!!!

        【讨论】:

          【解决方案9】:

          这也发生在我身上,作为一名 Web 开发人员,我查看了 Developers Console,实际错误是因为 Firebase 的控制台在验证 JSON 文件时无法进行身份验证。

          所以我对网页进行了“刷新”,并且它起作用了。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-08-07
            • 1970-01-01
            相关资源
            最近更新 更多