Showing posts with label vb.net. Show all posts
Showing posts with label vb.net. Show all posts

Tuesday, July 28, 2015

Convert JSON into Datatable

JSON stands for JavaScript Object Notation is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

Basically, json is introduced in further two structures:
  1. A collection of key/value pair
  2. An ordered list of values
Today, we will not go into the details of this topic. A minor but very important thing we will see here that how to convert the json string into the datatable using asp.net

Assumingly, we are using NewtonJson.dll control for .NET framework 4.0 in our project.

As you can see below picture, we are importing newtonjson control with some few built-in .NET libraries.



Now see the below source code. Here, we are retrieving the json response by using httpwebrequest and Streamreader and put that into a string variable responseText and then json.



In the above picture, the red highlighted line of code indicating that how a response of json string converting into the datatable. We are using deserializeObject, the built-in method of newtonjson control and converting into the datatable. Now, you can bind it with Gridview, Datalist, Listview or any other control on the page.

Hope, it will work for you too.