Skip to content

ArgumentException: JSON must represent an object type. UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:50) UnityEngine.JsonUtility.FromJson[Goalkeeper] (System.String json) (at C:/buildslave/unity/build/Modules/JSONSerialize/Public/JsonUtility.bindings.cs:33) Proyecto26.HttpBase+<>c__DisplayClass5_0`1[Goalkeeper].<DefaultUnityWebRequest>b__0 (Proyecto26.RequestException err, Proyecto26.ResponseHelper res) Proyecto26.HttpBase+<CreateRequestAndRetry>d__0.MoveNext () UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) #54

@mhadji05

Description

@mhadji05

using Proyecto26;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class firebaseTEST : MonoBehaviour {

static string DB_URL = ""; // url deleted only now for security in my code exists

Coach coach = new Coach("coachP", "goalkeeperK", 10);

// Use this for initialization
void Start () {


    OnSubmit();
}


void OnSubmit()
{
    //PostToDatabase();  // i can Post

    RetrieveFromDatabase(); // i have a runtime red warning
}


private void PostToDatabase()
{
    int[] stats = new int[] { 5, 10, 3 };
    Coach coach = new Coach("coachP", "goalkeeperK", 50);
    Goalkeeper goalkeeper = new Goalkeeper("goalkeeperK", 15);
    
    RestClient.Post(DB_URL + coach.coachName + ".json", goalkeeper);

    
}

private void RetrieveFromDatabase()
{
    RestClient.Get<Goalkeeper>(DB_URL + "goalkeeperK" + ".json").Then(response =>
    {
        coach.goalkeeper= response;

        Debug.Log(coach.goalkeeper); //this line not printed in console

    });
}

}


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class Goalkeeper{

public string keeperName;
public int Totalstats;

public Goalkeeper(string keeperName, int Totalstats)
{
    this.keeperName = keeperName;
    this.Totalstats = Totalstats;
}

}


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class Coach {

public string coachName;
public Goalkeeper goalkeeper;



    public Coach(string coachName, string keeperName, int Totalstats)
{
    this.coachName = coachName;

    goalkeeper = new Goalkeeper(keeperName, Totalstats);

}

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions