JSON From Web

| |
  1. Use NuGet, search and install “Json.net” from Newtonsoft
  2. Visit json2csharp.com with the sample Json formatted text. json2csharp will create the public class for your json file/text
    1. Paste your Json text into the text box and click on the “Generate” button
    2. Copy the generated class into your code
  3. Create a dataGridView (Windows form) or GridView (Web Form)
#region Using Statements - Start
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Newtonsoft.Json;
using System.Net;
#endregion Using Statements - Stop


namespace JSONFromWeb
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			DownloadJson("<Your Json URL>");
		}

		public void DownloadJson(string address)
		{
			WebClient wc = new WebClient();
			Uri uri = new Uri(address);
			wc.DownloadStringCompleted += (sender, e) =>
			{
				var deserialized =
					    JsonConvert.DeserializeObject<List<jsondata.MemberList>>(e.Result);
				dataGridView1.DataSource = deserialized;

			};

			wc.DownloadStringAsync(new Uri(address));
		}
	}
}

namespace jsondata
{
	public class MemberList
	{
		public string last_name { get; set; }
		public string first_name { get; set; }
		public string gender { get; set; }
		public string Address { get; set; }
		public string phone { get; set; }
		public double zip_lat { get; set; }
		public double zip_lon { get; set; }
		public double distance { get; set; }
	}
}
Originally Posted on June 18, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.