Integer fields in json data are being stored as Doubles in DataToken when using VRCJson.TryDeserializeFromJson in Udon#
Example Code:
DataToken data;
string json = "{ \"MyInt\": 12345 }";
if(VRCJson.TryDeserializeFromJson(json, out data))
{
Debug.Log("Int" + ((DataDictionary)data)["MyInt"].Int.ToString());
}
causes exception:
[UdonSharp] Assets/JsonTest.cs(29,61): Udon runtime exception detected!
An exception occurred during EXTERN to 'VRCSDK3DataDataToken.__get_Int__SystemInt32'.
Parameter Addresses: 0x00000024, 0x00000025
Attempted to access Double token as Int
Recommend parsing the json data correctly or providing getters/casts with auto type conversion.
Casts would be the preferable auto type conversion.
While getters like .Int .Double .Float would throw if the type mismatches
If I'm casting, I'm expecting the type to cast properly.
Doing an
(Int)((Double)(my_data_token))
is pretty dumb from a typecasting standpoint.
If casting an invalid format, like a dict/list to an int, then I would expect an exception.
strings I don't have a great opinion on. I think it would nice to run a Int64.Parse when casting a string to an int, but it would be acceptable to just throw a "cannot convert string to int" and expect the json to be formated properly