Having a structure for nested json file as nested classes, when I write into json, always the json is empty.
public class Class1
{
public int level;
public float timeElapsed;
public string playerName;
public Class2 subClass;
}
public class Class2
{
public int age;
}
Class2 class2= new Class2();
class2.age = 99;
Class1 myObject = new Class1();
myObject.level = 1;
myObject.timeElapsed = 47.5f;
myObject.playerName = "Francis";
myObject.subClass = class2;
jsonString = JsonUtility.ToJson(myObject);
print(jsonString);
I am getting {"level":1,"timeElapsed":47.5,"playerName":"Francis"}, where is the age ?!