C#、Python混合编程
# C# Python 混合编程,参数传递 C# Python mixing programming, Passing variable from C# to Python
采用序列化方式
- 数组
somemethod(param=[1,2])
1
var param = new int []{1,2}
call_python_method(SerializeJsonObject(param))
public static string SerializeJsonObject(object jsonObject)
{
using (var ms = new MemoryStream())
{
new DataContractJsonSerializer(jsonObject.GetType(),
new DataContractJsonSerializerSettings()
{
DateTimeFormat = new DateTimeFormat("yyyy-MM-dd' 'HH:mm:ss")
}
).WriteObject(ms, jsonObject);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
上次更新: 2022/11/09, 21:16:02