Closed pugwonk closed 1 day ago
Hi there,
I can see from your code sample you've JSON-serialized the result to an Azure Storage location and are attempting to deserialize it. You are using the JsonConvert
type which comes from the Newtonsoft.Json library to do this deserialization and I'm also assuming you used Newtonsoft.Json library to perform the serialization during storage.
My library uses Microsoft's System.Text.Json
library to perform all JSON manipulation. The property you reference is returned from iRacing as an integer. That integer represents the time as ten-thousandths of a second. To make this easier to work with in .NET code I convert that integer into a .NET TimeSpan
type using a converter class.
You can see the converter referenced via an attribute on the property itself in this snippet:
[JsonPropertyName("event_average_lap"), JsonConverter(typeof(TenThousandthSecondDurationNotNullConverter))]
public TimeSpan EventAverageLap { get; set; }
Unfortunately using the NewtonSoft.Json library the System.Text.Json converter is not picked up, so it performs the default behaviour when serializing a TimeSpan and converts it to a string.
I assume if Newtonsoft.Json serialised it then it should be able to de-serialize it. The alternative is to re-query the results from iRacing directly and use System.Text.Json to re-serialize the results, which will then pick up the attributes and use the converter.
Note also that the property name, "event_average_lap", hasn't been preserved because the JsonPropertyName
attribute is another System.Text.Json class. Instead Newtonsoft.Json has used the C# property name of "EventAverageLap".
Many thanks for taking a look at this - I think my issue is that, in the most recent JSON race results I got from iRacing, EventAverageLap seems to be a string with a timespan in it, rather than an int.
I'm still getting the same integer value as previous when I look at the raw result from iRacing's "/data" API.
If I query the /data/results/get
endpoint the result includes the following properties (entire result is not included, just some important properties):
{
"subsession_id": 72324726,
"end_time": "2024-10-27T11:46:33Z",
"event_average_lap": 791567,
"event_best_lap_time": 774481,
}
You can see here that "event_average_lap" is still an integer.
If you are seeing the property with the name "EventAverageLap" then that property isn't coming from iRacing directly. It is passing through this library and being interpreted as a .NET "TimeSpan" object and then serialized without the "System.Text.Json" Attributes for the name or converter being used.
I see - many apologies. I had actually totally forgotten that I was serializing and deserializing these. Something must have gone wrong somewhere else in that stack!
Many thanks for the API btw, it's invaluable for what I'm doing!
No worries! No need to apologise, thanks for your kind words. Hope the library keeps being useful & please feel free to reach out if you have any questions, concerns, or suggestions.
I have this code:
SubSessionResult rf = JsonConvert.DeserializeObject<SubSessionResult>(await ((CloudBlockBlob)item).DownloadTextAsync());
I've been using it to parse race results. Today it failed on a results set, and I think maybe the data types have changed. Normally, events have a EventAverageLap that appears to be an int... today I got a result with this in it:"EventAverageLap":"00:01:25.6086000"
Is it possible the schema has changed on the iRacing end?