C # conversion between XML and Json

Source: Internet
Author: User

This conversion is actually very simple. The most important thing is to reference the class library first. You can go to the official website to download reference http://json.codeplex.com.

Two days ago I learned Jquery ajax submit Json background processing article link for http://www.cnblogs.com/aehyok/archive/2013/05/18/3085499.html

Xml =;

This is an xml string pre-defined in the Code.

XmlDocument doc =

Then, read the xml string into the XML document.

JsonText =

Then, use the method specified in the Json. Net class library for conversion.
The running result is:

Json string in the first format

Json =;

The predefined Json string is as follows:
Similarly, the method in the Json. Net class library is called.

XmlDocument doc1 =

Json string in the second format

Json_str = json1 = + json_str +;

Call in the same way

XmlDocument doc2 =

Result:

 

The call is very simple. As long as the passed XML or Json string format is correct, it is not difficult to get the desired result. The code can be copied directly.

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.