I am trying to show JSON from the URL but it always fails. Please help me so that my script can run.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" Text="Get Station Information" runat="server" OnClick="GetStationInfo" />
<hr />
<asp:Label ID="lblID" runat="server" />
<asp:Label ID="lblCreated" runat="server" />
<asp:Label ID="lblUpdated" runat="server" />
<asp:Label ID="lblExternal" runat="server" />
<asp:Label ID="lblName" runat="server" />
<asp:Label ID="lblLongtitude" runat="server" />
<asp:Label ID="lblAltitude" runat="server" />
<asp:Label ID="lblRank" runat="server" />
</div>
</form>
</body>
</html>
Imports System.Net
Imports System.Web.Script.Serialization
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub GetStationInfo(sender As Object, e As EventArgs)
Dim url As String = String.Format("http://samples.openweathermap.org/data/3.0/stations?appid=b1b15e88fa797225412429c1c50c122a1")
Using client As New WebClient()
Dim json As String = client.DownloadString(url)
Dim stationInfo As StationInfo = (New JavaScriptSerializer()).Deserialize(Of StationInfo)(json)
lblID.Text = stationInfo.isiData.id
lblCreated.Text = stationInfo.isiData.created_at
lblUpdated.Text = stationInfo.isiData.updated_at
lblExternal.Text = stationInfo.isiData.external
lblName.Text = stationInfo.isiData.name
lblLongtitude.Text = stationInfo.isiData.longtitude
lblAltitude.Text = stationInfo.isiData.altitude
lblRank.Text = stationInfo.isiData.rank
End Using
End Sub
Public Class StationInfo
Public Property isiData As IsiData
End Class
Public Class IsiData
Public Property id As String
Public Property created_at As String
Public Property updated_at As String
Public Property external As String
Public Property name As String
Public Property longtitude As String
Public Property altitude As String
Public Property rank As String
End Class
End Class