for my Unity game I created a JSON file that holds the speedrun times. The saved times are Timespan strings. When loading the data I parse the strings to Timespan values. When saving the time I save the Timespan as a string to the file.
Example level in the JSON file:
{
"id": 1,
"personalBest": "00:00:00.0001336",
"perfectTime": "00:00:00.0001335",
}
If a level is not passed yet I want the personalBest property having the value null
instead of something like this
00:00:00.0000000
or
99:99:99.9999999
In my serializable class I currently have this code
[Serializable]
public class Level
{
public int id;
public string? personalBest; // this value could be null
public string perfectTime;
}
But I get this error
CS0453 The type 'string' must be a non-nullable type in order to use it as parameter T in the generic type or method 'System.Nullable'
Is a workaround possible?