Friday, 6 February 2015

Using C# dynamic type and NewtonSoft.Json to deserialize JSON

Today I had a requirement to poke a JSON api and capture the response as part of a payment gateway, all from my C# code-behind in a .Net webforms project. Dynamic seemed a good way to go:
                var results = JsonConvert.DeserializeObject(jsonResponseFromApi);
                var oneThingIWant = results.thingYouWant;
                var anotherThingIWant = results.something.somethingDeeper;