- Use NuGet, search and install “Json.net” from Newtonsoft
- Visit json2csharp.com with the sample Json formatted text. json2csharp will create the public class for your json file/text
- Paste your Json text into the text box and click on the “Generate” button
- Copy the generated class into your code
- 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; } } }
Last Updated on October 26, 2015