Hi All,
I am working on a projection where a dataset should be converted to a Json string and now I am facing a problem. Upon my requirement I have developed the Json string in two methods..
Method 1
DataSet -----> Xml ---------> Json
Code Block
XmlDocument documentSection = new XmlDocument();
documentSection.LoadXml(ServiceLevelDetails.GetXml());
strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(documentSection).TrimStart('{'));
Method 2 :
public string GetJson(DataTable dt)
{
logInfo.WriteToLog("JsonChannelDetailsService", string.Format("Entered GetJson() function sucessfully."), "INFO", "GetJson()");
System.Web.Script.Serialization.JavaScriptSerializer JSSerializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> DtRows =
new List<Dictionary<string, object>>();
Dictionary<string, object> newrow = null;
logInfo.WriteToLog("JsonChannelDetailsService", string.Format("Entered GetJson() function sucessfully."), "INFO", "GetJson()");
foreach (DataRow drow in dt.Rows)
{
newrow = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
newrow.Add(col.ColumnName.Trim(), drow[col]);
}
DtRows.Add(newrow);
}
return JSSerializer.Serialize(DtRows);
}
Here I am unable to see the Null or empty columns after json generation... Please let me know the procedure to show the null or empty columns aslo by two methods... Thanks in advance