Tuesday, 15 July 2014

DataSet to JSON, JSON to DataSet , and JSON to DataTable C#

DataSet to JSON
using Newtonsoft.Json;
         //objUserValidation is dataset variable and it contains tables
string jsonValue = JsonConvert.SerializeObject(objUserValidation, Formatting.Indented);


 JSON to DataSet
  using Newtonsoft.Json; 

             System.Data.DataSet ds = new System.Data.DataSet();
                System.Xml.XmlDocument xd = new System.Xml.XmlDocument();

               //jsonValue it contains json value
                 xd = (System.Xml.XmlDocument)JsonConvert.DeserializeXmlNode(jsonValue.ToString(), "jsonValue");

                ds.ReadXml(new System.Xml.XmlNodeReader(xd));