ASPX background generating JSON objects

Source: Internet
Author: User

JSON objects are widely used, and sometimes we need to use the following methods to convert some of the data into JSON objects.

1, the use of Newtonsoft.Json.DLL (recommended use)

: Http://files.cnblogs.com/files/love522/Newtonsoft.Json.zip

After downloading, add to the project, the code is as follows:

string json = Newtonsoft.Json.JsonConvert.SerializeObject (data); Data is the source, DataTable or list, etc. can be

2. Using the ASP. Json Conversion Tool (System.Runtime.Serialization.Json.dll)

Add the DLL to your project with the following code:

New DataContractJsonSerializer (data. GetType ());  // with the Dictionary object, you can convert directly, and if you use table, add a tablename to the table.  usingnew  MemoryStream ()) {     serializer. WriteObject (ms,data);      string json = System.Text.Encoding.UTF8.GetString (Ms. ToArray ());}

ASPX background generating JSON objects

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.