The debug(www) shows that the JSON object is correct and includes “age” : 20 but the debug(nomre.age) shows 0. There’s no warning or error in my code, I just don’t get it. Thanks for your help guru!
How does the JSON look, and what does the first debug statement return?
EDIT: It looks like you’re running CreateFromJSON(), and throwing the result away. You’re not saving it anywhere, so you never set age to anything, so it’s the default int value of 0.
Thanks Boz0r
JSON as Debug return is {“age” : 20} from a UnityWebRequest
Reading Unity - Scripting API: JsonUtility.FromJson I understand that returnJsonUtility.FromJson(jsonString) populates all variables (age here).
I think you’re pointing me in the right direction but can’t get how to populate nomre variables. Can you write a quick example?
public class Caller : MonoBehaviour
{
public void GetJson()
{
string jsonity = www.downloadHandler.text;
Debug.Log("www."+ jsonity);
// You need to add the result from CreateFromJson to a variable, as you don't set it in the originl object.
var result = nomre.CreateFromJSON(jsonity);
Debug.Log("age: "+ result.age);
}
}
JsonUtility.FromJsonOverwrite(jsonString, this); works from within the Monobehaviour class … 6 hours lost. My stupid bad. c# - Saving/loading data in Unity - Stack Overflow is what is missing in Unity doc.