06-09-2025, 06:33 AM
The following code works, though I haven’t done extensive testing.
Can a list object be stored using a QM array?
How should JSON objects be handled? This is used frequently — is it possible to convert them into XML objects?
Handling a few common object types would be sufficient, such as: strings, integers, string arrays, and JSON strings.
Can a list object be stored using a QM array?
How should JSON objects be handled? This is used frequently — is it possible to convert them into XML objects?
Handling a few common object types would be sufficient, such as: strings, integers, string arrays, and JSON strings.
switch (result.GetPythonType().Name)
{
case "bool":
return result.As<bool>();
case "int":
return result.As<int>();
case "float":
return result.As<double>();
case "str":
return result.As<string>();
case "list":
var list = new List<object>();
dynamic pyList = result;
foreach (var item in pyList)
{
list.Add(item);
}
return list;
case "dict":
var dict = new Dictionary<object, object>();
dynamic pyDict = result;
foreach (var key in pyDict.keys())
{
dict[key] = pyDict[key];
}
return dict;
default:
try
{
return result.As<object>();
}
catch
{
return result.ToString();
}
}