unity json
public class MyClass
{
public int level;
public float timeElapsed;
public string playerName;
}
// Start is called before the first frame update
void Start()
{
MyClass myObject = new MyClass();
myObject.level = 1;
myObject.timeElapsed = 47.5f;
myObject.playerName = "zyx";
string json = JsonUtility.ToJson(myObject);
print("json: " + json);
MyClass myObject1 = new MyClass();
myObject1 = JsonUtility.FromJson<MyClass>(json);
print("playerName: " + myObject1.playerName);
List<MyClass> ml = new List<MyClass>();
myObject.level = 1;
myObject.timeElapsed = 47.5f;
myObject.playerName = "zyx";
ml.Add(myObject);
myObject.level = 2;
myObject.timeElapsed = 47.5f;
myObject.playerName = "wb";
ml.Add(myObject);
string jsonToSave = JsonUtility.ToJson(ml);
print("jsonToSave: " + jsonToSave);
}