Muhammad Faizan Khan
Muhammad Faizan Khan

Reputation: 10561

Sending data from unity to firebase producing error - Invalid data; couldn't parse JSON object

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.

Upvotes: 0

Views: 1174

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599766

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.

Upvotes: 2

Related Questions