I have been looking at how to easily consume json from C#.
Given the source of the data I don’t want to create specific types (I’ll be creating a dynamic wpf control to allow editing of json read from a configuration database).
This requires newtonsoft.json to be pulled from nuget and a reference made to newtonsoft.json.
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace SimpleJsonTest
{
class Program
{
static void Main(string[] args)
{
string json = @"[{""First"":""Chris"",""LastName"":""Pietschmann""}, {""First"":""Chris"",""LastName"":""Eyre""}]";
List<Dictionary> values = JsonConvert.DeserializeObject<List<Dictionary>>(json);
Console.WriteLine( string.Join(",", values[0].Keys));
Console.WriteLine(string.Join(",", values[0].Values));
Console.WriteLine(string.Join(",", values[1].Values));
Console.ReadLine();
}
}
}