Category >
ASP.NET
|| Published on :
Thursday, November 19, 2015 || Views:
11418
||
Download Json Data from URL Download Json Data Download Json Data from URL
Introduction
Here Pawan Kumar will explain how to Download Json Data from URL in Asp.Net using C sharp
Description
In previous post I have explained Create table from json jQuery with detailed example, How to Store Hashtable in Session using asp.net and C# with example, Zoom Feature for Query Text and Results Text in SQL Server Management Studio 2012, How to make How to make blinking/flashing text with CSS3 and jQuery, Format JSON Date String To Local DataTime Object Using JavaScript, How to replace number from a string in C#, and many more articles.
Now I will explain How to How to Download Json Data from URL in Asp.Net using C sharp
So follow the steps to learn How to Download Json Data from URL in Asp.Net using C sharp
In some situation, developer wants to download JSON data from a URL and then store it ina variable. In this particular example we are going to discuss the method to fetch data from a URL in JSON format in asp.net web application
Note: for this we have to use "System.Net.WebClient" class for download Json from the URL.
Below is the code for downloading JSON data from URL in ASP.NEt using C#
Step 1: Create a Website in Visual Studio 2010.
Step 2: Create a new asp.net web page(default.aspx)
Step 3: Write the below codes in code behind of default.aspx webpage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Web.Script.Serialization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
downloadjsonfromweb();
}
private void downloadjsonfromweb()
{
var w = new WebClient();
string url = "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=8s678k5fh3gfdta9z742fkme";
var jsondata = string.Empty;
jsondata = w.DownloadString(url);
string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(jsondata);
}
public class test
{
public Dictionary<object, object> data { get; set; }
}
}
Conclusion:
So, In this tutorial we have learned, How to Download Json Data from URL in Asp.Net using C sharp
Download Source Codes