Firebase“无效数据,无法解析 JSON 对象......" [英] Firebase "Invalid data, couldn't parse JSON object...."

查看:30
本文介绍了Firebase“无效数据,无法解析 JSON 对象......"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make a POST request from Parse to Firebase, using Parse Cloud Code and Firebase's REST API.

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 响应以下错误:

However, this code makes Firebase respond with the following error:

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

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

I have tried a multitude of combinations for body, including variations of apostrophes, integers, and removing brackets altogether.

有什么想法吗?

推荐答案

回答我的问题:

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

JSON for Firebase must be wrapped in single quotes ':

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

这篇关于Firebase“无效数据,无法解析 JSON 对象......"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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