And then, after you finish everything, you'll need to convert that string back to dataset so that you can save the result into the database or display it.
In this entry I'll show you the easiest way to do that using Json.NET
Dataset to Json String
StringWriter sw = new StringWriter(); ds.WriteXml(sw, XmlWriteMode.IgnoreSchema); XmlDocument xd = new XmlDocument(); xd.LoadXml(sw.ToString()); string jsonText = JsonConvert.SerializeXmlNode(xd); txtResult.Text = jsonText;First, if you want to convert DataSet to Json String you have to convert DataSet to XMLDocument (Here I use StringWritter).
When you've already added Newtonsoft.Json.Net to you References, you can use JsonConvert to convert between JSON and XML. If you want to convert o JSON String, use SerializeXmlNode. This method takes an XmlNode and serializes it to JSON text.
Json String to Dataset
XmlDocument xd = new XmlDocument(); xd = (XmlDocument)JsonConvert.DeserializeXmlNode(txtStr.Text); DataSet ds = new DataSet(); ds.ReadXml(new XmlNodeReader(xd)); //Once you have your dataset, you can use it to save data into database or display it gvCustomers.DataSource = ds.Tables; gvCustomers.DataBind();To do this, we use method DeserializeXmlNode on JsonConvert. This method takes JSON text and deserializes it into a XmlNode. And we can easily convert it into DataSet using method ReadXml.
So, I think that's enough for this entry. If you want to find out more, visit Json.NET to download the full project as well as documentations.
Hope this entry help you!
If you found any mistake or error in this entry, please let me know. I'll try to fix that a.s.a.p.
Any solution is highly appreciated!