从统一发送数据到firebase生成错误 - 数据无效;无法解析JSON对象 [英] Sending data from unity to firebase producing error - Invalid data; couldn't parse JSON object

查看:167
本文介绍了从统一发送数据到firebase生成错误 - 数据无效;无法解析JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要使用Unity3d与Firebase我有一个数据库的网址,我想发送数据。
我正在使用的代码

  void开始()
{
BtnSendScore();


public void BtnSendScore(){
StartCoroutine(SendScore(Muhammad Faizan Khan,100));

$ b $ public IEnumerator SendScore(string name,int score){

string url =https://xyz.firebaseio.com/scores.json ;
WWWForm objForm = new WWWForm();
objForm.AddField(playerName,name);
objForm.AddField(score,score);
objForm.AddField(scoreDate,DateTime.Now.ToString());
WWW www = new WWW(url,objForm);
产量回报www;

if(www.error == null)
{
Debug.Log(Adedd ::+ www.data);
}
else {
Debug.LogError(Error ::+ www.error);


$ / code $ / pre

发现这个错误?什么问题是我检查与jQuery的Stackoverflow谈论stringify。


Adedd :: {error:无效的数据; couldn解析JSON对象,
数组或值,也许你在关键的
名字中使用了无效字符。请记住,我没有在Firebase的数据库只是创建数据库和网址搞乱数据库。使用REST API写入Firebase数据库,您需要将数据以JSON的形式传递给Firebase数据库在请求的正文中。 Firebase REST API不会将数据作为表单参数。请参阅 Firebase文档,了解API如何工作的一些示例。 / p>

这篇文章看起来像一个有前途的起点,因为这个答案


Just use Unity3d with Firebase I have a url of database where i want to send data. Code below i am using

 void Start()
    {
        BtnSendScore();
    }

    public void BtnSendScore() {
        StartCoroutine(SendScore("Muhammad Faizan Khan", 100));
    }

    public IEnumerator SendScore(string name, int score){

        string url = "https://xyz.firebaseio.com/scores.json";
        WWWForm objForm =new  WWWForm();
        objForm.AddField("playerName", name);
        objForm.AddField("score", score);
        objForm.AddField("scoreDate", DateTime.Now.ToString());
        WWW www = new WWW(url, objForm);
        yield return www;

        if (www.error == null)
        {
            Debug.Log("Adedd ::" + www.data);
        }
        else {
            Debug.LogError("Error ::" + www.error);
        }
    }

Found this error? What the problem is i check on stackoverflow with jquery it talking about stringify.

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

Remember I didn't mess with database in firebase just create database and got url. No keys added.

解决方案

To write to the Firebase Database using the REST API, you'll need to pass the data as JSON in the body of the request. The Firebase REST API does not take the data as form parameters. See the Firebase documentation for some examples of how the API works.

This post looks like a promising starting point as does this answer.

这篇关于从统一发送数据到firebase生成错误 - 数据无效;无法解析JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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