public static class JsonTester {
public static void Test() {
List<ServerInfo> playerInstances = new List<ServerInfo>();
ServerInfo playerInstance1 = new ServerInfo();
playerInstance1.ServerName = "8484239823";
playerInstance1.SavedPort = "Powai";
playerInstance1.SavedIP = "Random Nick";
ServerInfo playerInstance2 = new ServerInfo();
playerInstance2.ServerName = "512343283";
playerInstance2.SavedPort = "User2";
playerInstance2.SavedIP = "Rand Nick 2";
playerInstances.Add(playerInstance2);
playerInstances.Add(playerInstance1);
Log.Message(playerInstances[0].ServerName);
// To Json
string stringListAsJson = JsonUtility.ToJson(new JsonableListWrapper<ServerInfo>(playerInstances));
Log.Message(stringListAsJson);
// From Json
List<ServerInfo> stringListFromJson = JsonUtility.FromJson<JsonableListWrapper<ServerInfo>>(stringListAsJson).list;
Log.Message("Here");
//Convert to JSON
Log.Message(stringListFromJson.Count.ToString());
//Log.Message(stringListFromJson[0].ServerName);
}
}
[System.Serializable]
public class JsonableListWrapper<T>
{
public List<T> list;
public JsonableListWrapper(List<T> list) => this.list = list;
}