Hi amar,
Use Newtonsoft.Json library.
Refer below sample.
HTML
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { Id = 1, Name = "John Hammond", Country = "United States" });
customers.Add(new Customer { Id = 2, Name = "Mudassar Khan", Country = "India" });
customers.Add(new Customer { Id = 3, Name = "Suzanne Mathews", Country = "France" });
customers.Add(new Customer { Id = 4, Name = "Robert Schidner", Country = "Russia" });
string json = Newtonsoft.Json.JsonConvert.SerializeObject(customers);
System.Data.DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Data.DataTable>(json);
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim customers As List(Of Customer) = New List(Of Customer)()
customers.Add(New Customer With {
.Id = 1,
.Name = "John Hammond",
.Country = "United States"
})
customers.Add(New Customer With {
.Id = 2,
.Name = "Mudassar Khan",
.Country = "India"
})
customers.Add(New Customer With {
.Id = 3,
.Name = "Suzanne Mathews",
.Country = "France"
})
customers.Add(New Customer With {
.Id = 4,
.Name = "Robert Schidner",
.Country = "Russia"
})
Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(customers)
Dim dt As Data.DataTable = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Data.DataTable)(json)
gvDetails.DataSource = dt
gvDetails.DataBind()
End Sub
Public Class Customer
Public Property Id As Integer
Public Property Name As String
Public Property Country As String
End Class
Screenshot