Sunday, May 11, 2014

How to Get(Download) Json Data from Url in Asp.Net

Sometime in we need to download json data from a url and then store it in a variable. In this example I am going to discus the way to fetch data from a url which return data in json format in your web application.

System.Net.WebClient class contain the method DownloadString() to download json from a url.

Example showing the code of Downloading json data from URL in Asp.Net using C#:

Add the Following code in Code Behind :

Add Namespace: 
using System.Net;

protected void Page_Load(object sender, EventArgs e)

    private void downloadjson()
    {   var w = new WebClient();
        string url = "";
        var jsondata = string.Empty;
        jsondata = w.DownloadString(url);
        var result = JsonConvert.DeserializeObject<test>(jsondata);
    public class test

        public Dictionary<object, object> data { get; set; }

Sample Output: