In this article I will explain with an example, how to consume (call) JSON Web Service in ASP.Net using C# and VB.Net.
This article will illustrate consuming (calling) JSON Web Service in ASP.Net by making call to a Weather Web Service.
The Weather API
This article makes use of the OpenWeatherMap Weather API service. It allows free requests upto certain limit. You will need to register and get an API Key (AppId) using the following link.
HTML Markup
The HTML Markup consists of a TextBox, a Button and an HTML Table with Labels and Image controls.
<asp:TextBox ID="txtCity" runat="server" Text="" />
<asp:Button Text="Get Weather Information" runat="server" OnClick="GetWeatherInfo" />
<hr />
<table id="tblWeather" runat="server" border="0" cellpadding="0" cellspacing="0"
        <th colspan="2">
            Weather Information
        <td rowspan="3">
            <asp:Image ID="imgWeatherIcon" runat="server" />
            <asp:Label ID="lblCity_Country" runat="server" />
            <asp:Image ID="imgCountryFlag" runat="server" />
            <asp:Label ID="lblDescription" runat="server" />
            <asp:Label ID="lblHumidity" runat="server" />
            <asp:Label ID="lblTempMin" runat="server" />
            <asp:Label ID="lblTempMax" runat="server" />
            <asp:Label ID="lblTempDay" runat="server" />
            <asp:Label ID="lblTempNight" runat="server" />)
You will need to import the following namespaces.
using System.Net;
using System.Web.Script.Serialization;
Imports System.Net
Imports System.Web.Script.Serialization
Property classes
You will need to use the following Property classes to hold the JSON data returned from the Weather API web service.
public class WeatherInfo
    public City city { get; set; }
    public List<List> list { get; set; }
public class City
    public string name { get; set; }
    public string country { get; set; }
public class Temp
    public double day { get; set; }
    public double min { get; set; }
    public double max { get; set; }
    public double night { get; set; }
public class Weather
    public string description { get; set; }
    public string icon { get; set; }
public class List
    public Temp temp { get; set; }
    public int humidity { get; set; }
    public List<Weather> weather { get; set; }
Public Class WeatherInfo
    Public Property city As City
    Public Property list As List(Of List)
End Class
Public Class City
    Public Property name As String
    Public Property country As String
End Class
Public Class Temp
    Public Property day As Double
    Public Property min As Double
    Public Property max As Double
    Public Property night As Double
End Class
Public Class Weather
    Public Property description As String
    Public Property icon As String
End Class
Public Class List
    Public Property temp As Temp
    Public Property humidity As Integer
    Public Property weather As List(Of Weather)
End Class
Displaying daily Weather Forecast using Weather API in ASP.Net
When the Button is clicked, the following event handler is executed. The name of the City or Zip Code is passed along with the API Key (AppId) to the Weather API web service using the WebClient class.
The Weather API web service returns the daily Weather Forecast information in JSON format.
The JSON string is deserialized to the Property class object and finally the details are displayed in the respective fields of the HTML Table.
protected void GetWeatherInfo(object sender, EventArgs e)
    string appId = "<App Id>";
    string url = string.Format("{0}&units=metric&cnt=1&APPID={1}", txtCity.Text.Trim(), appId);
    using (WebClient client = new WebClient())
        string json = client.DownloadString(url);
        WeatherInfo weatherInfo = (new JavaScriptSerializer()).Deserialize<WeatherInfo>(json);
        lblCity_Country.Text = + "," +;
        imgCountryFlag.ImageUrl = string.Format("{0}.png",;
        lblDescription.Text = weatherInfo.list[0].weather[0].description;
        imgWeatherIcon.ImageUrl = string.Format("{0}.png", weatherInfo.list[0].weather[0].icon);
        lblTempMin.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.min, 1));
        lblTempMax.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.max, 1));
        lblTempDay.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0], 1));
        lblTempNight.Text = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.night, 1));
        lblHumidity.Text = weatherInfo.list[0].humidity.ToString();
        tblWeather.Visible = true;
Protected Sub GetWeatherInfo(sender As Object, e As EventArgs)
    Dim appId As String = "<App Id>"
    Dim url As String = String.Format("{0}&units=metric&cnt=1&APPID={1}", txtCity.Text.Trim(), appId)
    Using client As New WebClient()
        Dim json As String = client.DownloadString(url)
        Dim weatherInfo As WeatherInfo = (New JavaScriptSerializer()).Deserialize(Of WeatherInfo)(json)
        lblCity_Country.Text = + "," +
        imgCountryFlag.ImageUrl = String.Format("{0}.png",
        lblDescription.Text = weatherInfo.list(0).weather(0).description
        imgWeatherIcon.ImageUrl = String.Format("{0}.png", weatherInfo.list(0).weather(0).icon)
        lblTempMin.Text = String.Format("{0}°С", Math.Round(weatherInfo.list(0).temp.min, 1))
        lblTempMax.Text = String.Format("{0}°С", Math.Round(weatherInfo.list(0).temp.max, 1))
        lblTempDay.Text = String.Format("{0}°С", Math.Round(weatherInfo.list(0), 1))
        lblTempNight.Text = String.Format("{0}°С", Math.Round(weatherInfo.list(0).temp.night, 1))
        lblHumidity.Text = weatherInfo.list(0).humidity.ToString()
        tblWeather.Visible = True
    End Using
End Sub
Consume (Call) JSON Web Service in ASP.Net using C# and VB.Net