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

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

问题描述



 我试图使用Parse Cloud Code和Firebase的REST API从Parse发送POST请求到Firebase。 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(成功发布hello!);
},函数(httpResponse){
response.error(failed to post hello+ httpResponse.text)
})$ b $但是,这段代码让Firebase回应了以下错误:

 无效的数据;无法解析JSON对象,数组或值,也许您在密钥名称中使用了无效字符。 

我已经尝试了 body ,包括撇号,整数和删除括号的变化。



有什么想法?

解决方案

回答我的问题:



Firebase的JSON必须用单引号包装'

body:'{hi:hello}'


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)
  })
})

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."

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

Any ideas?

解决方案

Answering my question:

JSON for Firebase must be wrapped in single quotes ':

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

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

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