- Joined
- Dec 1, 2019
- Messages
- 80
Running into an issue, not sure whether or not what I'm doing is expected to be supported. I try to deserialize a json str to an array of custom types.
The following C#
generates the following lua
which errs with..
war3.map.lua.18851: attempt to index a nil value (upvalue 'SystemTextJson')
I can deserialize the same constant string in a standalone c# console app using the same types.
The following C#
Code:
static public void LoadInputData(string jsonStr)
{
if (!m_bLoadedInputData)
{
try
{
m_UnitInputData = System.Text.Json.JsonSerializer.Deserialize<InputData.Unit[]>(jsonStr);
Log.Quick("Deserialized json");
}
catch(Exception e)
{
Log.Error(e.Message);
}
m_bLoadedInputData = true;
}
else
{
Log.Error("Attempting to load input data from json str after it's already been loaded.");
}
}
generates the following lua
Code:
LoadInputData = function (unitInputData)
if not m_bLoadedInputData then
class.m_UnitInputData = unitInputData
m_bLoadedInputData = true
else
Helpers.Log.Error("Attempting to load input data from array after it's already been loaded.", 30)
end
end
LoadInputData1 = function (jsonStr)
if not m_bLoadedInputData then
System.try(function ()
/*18851:*/ class.m_UnitInputData = SystemTextJson.JsonSerializer.Deserialize(jsonStr, nil, ArrayUnit)
Helpers.Log.Quick("Deserialized json", 15)
end, function (default)
local e = default
Helpers.Log.Error(e:getMessage(), 30)
end)
m_bLoadedInputData = true
else
Helpers.Log.Error("Attempting to load input data from json str after it's already been loaded.", 30)
end
end
InitFromInputData = function ()
if not m_bLoadedInputData then
Helpers.Log.Error("Attempting to init data but no input data has been laoded.", 30)
end
which errs with..
war3.map.lua.18851: attempt to index a nil value (upvalue 'SystemTextJson')
I can deserialize the same constant string in a standalone c# console app using the same types.
Last edited: