"Original" intermediate file for object conversion using JSON as Python and C # mixed programming

Source: Internet
Author: User

First, Python custom class object JSON string of steps [1]

1. Use JSON or Simplejson to do it;

2. Define the conversion function:

3. Defining classes

4. Generating objects

5.dumps execution, introducing conversion functions

Specifically, if it is a python built-in object, such as a list, FLOAT,STR, etc., no conversion function is required. Otherwise, the JSON module cannot be processed by default and throws an exception: TypeError xx is not JSON serializable

My Code:

Second, generate a JSON string containing the list of objects in Python and write it to a file with the following code:

Third, the JSON file is parsed on the C # side:

1, first define the product class, the code is as follows:

2. Use NewtonSoft.JSon.dll to directly convert the JSon file to a list of objects. Newtonsoft.Json.dll must first be introduced into the project, the code is as follows:

Iv. Reference Documents:

"1" Python custom class object JSON string method, http://blog.csdn.net/superch0054/article/details/12065727

"2" Newtonsoft.json uses C # sequence number Json, deserializes objects, http://blog.sina.com.cn/s/blog_4d38a3b001019pzi.html

"Original" intermediate file for object conversion using JSON as Python and C # mixed programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.