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