// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using Newtonsoft.Json; namespace JsonProc.BindNewton { public class Employee { public Employee() : this(0, "", "") { } public Employee(int no, string name, string role) { this.No = no; this.Name = name; this.Role = role; } public int No { get; set; } public string Name { get; set; } public string Role { get; set; } public override string ToString() { return string.Format("[{0},{1},{2}]", No, Name, Role); } } public class Program { private const string json = "[ { \"no\" : 1, \"name\" : \"Alan A\", \"role\" : \"Manager\" }, " + "{ \"no\" : 2, \"name\" : \"Brian B\", \"role\" : \"Engineer\" }, " + "{ \"no\" : 3, \"name\" : \"Chris C\", \"role\" : \"Sales rep\" } ]"; public static void Main(string[] args) { // read Employee[] employees = JsonConvert.DeserializeObject(json); foreach (Employee employee in employees) { Console.WriteLine(employee); } // write Console.WriteLine(JsonConvert.SerializeObject(employees)); } } }