【问题标题】:Firebase "Invalid data, couldn't parse JSON object...."Firebase“无效数据,无法解析 JSON 对象......”
【发布时间】:2015-11-13 00:07:01
【问题描述】:

我正在尝试使用 Parse Cloud Code 和 Firebase 的 REST API 从 Parse 向 Firebase 发出 POST 请求。

Parse.Cloud.define("createChatRoom", function(request, response) {

  Parse.Cloud.httpRequest({
    url: 'https://myapp.firebaseIO.com/' + '.json',
    method: 'PUT',
    body: {"hi": "hello"}
  }).then(function(httpResponse) {
      response.success("Successfully posted hello!");
  },function(httpResponse) {
      response.error("failed to post hello" + httpResponse.text)
  })
})

但是,此代码使 Firebase 响应以下错误:

"Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."

我已经为body 尝试了多种组合,包括撇号、整数的变体以及完全删除括号。

有什么想法吗?

【问题讨论】:

    标签: json parse-platform firebase


    【解决方案1】:

    回答我的问题:

    Firebase 的 JSON 必须用单引号括起来 ':

    body: '{"hi": "hello"}'

    【讨论】:

      【解决方案2】:

      我觉得这样使用比较好body: JSON.stringify({"hi": "hello"})

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-25
        • 1970-01-01
        相关资源
        最近更新 更多