converting datasets to JSON

Source: Internet
Author: User

converting datasets to JSON

First step: Create a new class object I usually write three properties: state, return information, data set

Step Two: Create a new JSON transformation class

Step three: Pass the class object as a parameter into the JSON transformation class

——————————————————————————————————————————————————————————————————————————————

 ///<summary>
       //Data set to JSON
        //</summary>
       //<param name= "obj "> Data set </param>
       //<returns>json Format Data </returns
        public static string Datatojson (Object obj)
         {
            try
            {
                //serialization and deserialization control
                 jsonserializersettings settings = new Jsonserializersettings ();


Settings. referenceloophandling = referenceloophandling.include;//serialization and deserialization Yes, contains default values
Serialization and deserialization Yes, ignoring default values
Settings. referenceloophandling = Referenceloophandling.ignore;


Set Date format
Settings. dateformatstring = "YYYY-MM-DD";
Jsonproperty non-public members are serialized
Convert to JSON string
string result = Jsonconvert.serializeobject (obj, formatting.indented, settings);
return result;
}
catch (Exception ex)
{
Loghelper.writelog ("DataSet converted to JSON failed", ex);
Return "";
}
}

converting datasets to JSON

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.