Deserializing JSON using JSon.NET with dynamic data

The simplest method. In this particular case would probably be to go dynamic.

dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
var lastRevId = data.query.pages["6695"].lastrevid;

You can reference any element by it’s [] name so you can do something like data["query"]["pages"]["6695"]["lastrevid"]. This will get by all those little objects where the name isn’t valid in c#.

Leave a Comment