The JsonUtility class allows us to easily create JSON strings from individual objects, and also Lists of objects.
Creating JSON strings from individual objects and lists of objects
How to do it...
To create JSON strings from individual and Lists of objects perform the following steps:
- Create a new C# script class named PlayerScore:
using UnityEngine;
[System.Serializable]
public class PlayerScore {
public string name;
public int score;
public string ToJson() {
bool prettyPrintJson = true;
return JsonUtility.ToJson(this, prettyPrintJson);
}
}
- Create a new C# script class named PlayerScoreList:
using UnityEngine;
using System.Collections.Generic...