Weather application with the help of Json parsing

Today, I will create a weather application using Json.  

Today,  we will see an application that will give you the temperature of a country. You might have listen about the longitude and latitude. The lon. and lat. will help us to get the location of the country.
The question is what's the logic used in application. The answer is that i have created a button and the textblock in the mainpage.xaml and on the click event. A code has been generated that sync the json code from the website and convert the data ! After that the temperature is displayed. In this process we have installed Newtonsoft json package in visual studio. And a class is made that is the result of json code extraction.  Now lets see how the weather application will work.
 Lets first install the newton soft Json Package.

In the tool box go to the library package Manager then package manger console and click it. Below there write
Install Package Newtonsoft Json after writing this click enter. The package will install in your application.


 Now after that process lets come to the mainpage.xaml code. Here i have added a button and a textblock. Textblock will display the weather on click event of the button. 


Here is the API of Json that provides the information about the weather of specific city. It's actually Json code that the website will return. 


The code gained from the open weather api is pasted on a website that generate a C# class according to the data in the Json code. That class will be added on our project.


Here is the class that is added into the project.


Here is the main code in the button event. As you can see that the web address of that website is pasted in the client.DownloadStringAsync that will take the json code from the website. And the data obtained is converted into integer that is the temperature in kelvin. Which is converted in the Celsius. 


 
Here is the application that is currently giving the temperature of Lahore.

Comments

Popular posts from this blog

How to move an object in Unity 3D

Input.Getaxis, OnMouseDown, GetComponent< > - Unity Scripts

Vector Math - Unity