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