Hi Amitabha,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox runat="server" ID="txtPin" />
<asp:Button Text="Get PostOffice" runat="server" OnClick="GetDetails" /><hr />
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Namespaces
C#
using System.Collections.Generic;
using Newtonsoft.Json;
using RestSharp;
VB.Net
Imports System.Collections.Generic
Imports Newtonsoft.Json
Imports RestSharp
Code
C#
protected void GetDetails(object sender, EventArgs e)
{
string pin = txtPin.Text.Trim();
RestClient restClient = new RestClient(string.Format("{0}{1}", "https://api.postalpincode.in/pincode/", pin));
restClient.Timeout = -1;
RestRequest request = new RestRequest();
IRestResponse result = restClient.Execute(request);
PostOfficeDetails[] pd = JsonConvert.DeserializeObject<PostOfficeDetails[]>(result.Content);
this.gvDetails.DataSource = pd[0].PostOffice;
this.gvDetails.DataBind();
}
public class PostOfficeDetails
{
public string Message { get; set; }
public string Status { get; set; }
public List<PostOffice> PostOffice { get; set; }
}
public class PostOffice
{
public string Name { get; set; }
public string Description { get; set; }
public string BranchType { get; set; }
public string DeliveryStatus { get; set; }
public string Circle { get; set; }
public string District { get; set; }
public string Division { get; set; }
public string Region { get; set; }
public string Block { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string Pincode { get; set; }
}
VB.Net
Protected Sub GetDetails(ByVal sender As Object, ByVal e As EventArgs)
Dim pin As String = txtPin.Text.Trim()
Dim restClient As RestClient = New RestClient(String.Format("{0}{1}", "https://api.postalpincode.in/pincode/", pin))
restClient.Timeout = -1
Dim request As RestRequest = New RestRequest()
Dim result As IRestResponse = restClient.Execute(request)
Dim pd As PostOfficeDetails() = JsonConvert.DeserializeObject(Of PostOfficeDetails())(result.Content)
Me.gvDetails.DataSource = pd(0).PostOffice
Me.gvDetails.DataBind()
End Sub
Public Class PostOfficeDetails
Public Property Message As String
Public Property Status As String
Public Property PostOffice As List(Of PostOffice)
End Class
Public Class PostOffice
Public Property Name As String
Public Property Description As String
Public Property BranchType As String
Public Property DeliveryStatus As String
Public Property Circle As String
Public Property District As String
Public Property Division As String
Public Property Region As String
Public Property Block As String
Public Property State As String
Public Property Country As String
Public Property Pincode As String
End Class
Screenshot