简体   繁体   English

我如何将python对象作为参数传递给C#程序

[英]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.

相关问题 如何从 Python 将 ulong 类型参数传递给 C# 函数? - How do I pass a ulong type argument to a C# function from Python? C#:如何将对象数组作为参数传递 - C#: How to pass an object array as an argument 如何将结构从非托管C ++程序传递到C#程序? - How do I pass a struct from an unmanaged C++ program to a C# program? 如何将实体对象传递给C#中的函数 - How do I pass an Entity Object to a function in C# 如何将来自C#程序中Web浏览器小程序中加载的网页的参数传递回C#应用程序? - How can I pass an argument from a web page that is loaded inside a web browser applet in a C# program, back to the C# application? 如何从C#向Python脚本传递双引号作为参数? - How do you pass a double quote as an argument to python script from C#? 在ASP.net C#中,如何将参数从Javascript函数传递给onclick处理程序 - In ASP.net C# how do I pass an argument from a Javascript function to the onclick handler 如何使用C#在Python中将字符串作为命令行参数传递 - How to pass string as command line argument in python using C# 如何将2D数组作为参数从C#传递给python - How to pass a 2D array as argument from C# to python 将HashTable类型的ac#对象作为参数传递 - Pass a c# object of type HashTable as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM