The JsonUtility class allows us to easily parse (process) JSON strings and extract individual objects, and also Lists of objects.
Creating individual objects and Lists of objects from JSON strings
How to do it...
To create individual objects and Lists of objects from JSON strings, 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 static PlayerScore FromJSON(string jsonString) {
return JsonUtility.FromJson<PlayerScore>(jsonString);
}
}
- Create a new C# script class named PlayerScoreList:
using UnityEngine;
using...