[英]how do i pass python object as argument to C# program
I have a C# windows application, where i need to pass object created in python script - as argument to C# program and vice-verse. 我有一个C#Windows应用程序,我需要传递在python脚本中创建的对象-作为C#程序的参数,反之亦然。 So how do i pass object created by Python script to C# program as parameter.
因此,如何将Python脚本创建的对象作为参数传递给C#程序。
For this, i don't want to use Iron-Python . 为此,我不想使用Iron-Python 。 My strict requirement is to use object created by running the C Python scripts.
我的严格要求是使用通过运行C Python脚本创建的对象。 My Python script reads a json file and creates object.
我的Python脚本读取json文件并创建对象。
My sample Json string : 我的示例Json字符串:
{"?xml":{"@version":"1.0","@encoding":"Windows-1252"},"TestScript":{"TestExperiment":{"Test1":{"Control":[{"@Type":"System.Windows.Forms.TextBox","@Name":"Description","@FormName":"Test1","Text":null,"Visible":"True"},{"@Type":"System.Windows.Forms.TextBox","@Name":"Objective","@FormName":"Test1","Text":null,"Visible":"True"},{"@Type":"System.Windows.Forms.TextBox","@Name":"Test1","@FormName":"Test1","Text":null,"Visible":"True"}]}}}}
Thanks, 谢谢,
If your python objects are serialized as Json, I think you should first use the Json.net package to parse the input strings as Json Objects. 如果您的python对象被序列化为Json,我认为您应该首先使用Json.net包将输入字符串解析为Json对象。
For instance: 例如:
JObject obj = Jobject.Parse(jsonString);
After that, I would recommened you create C# objects that mirror your python objects and then deserialize them into real objects. 在那之后,我建议您创建镜像您的python对象的C#对象,然后将它们反序列化为真实对象。
For instance: 例如:
// Json String to Object
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(productJsonString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.