Deserialize Dynamic Json string using Newtonsoft JSON.NET Deserialize Dynamic Json string using Newtonsoft JSON.NET json json

Deserialize Dynamic Json string using Newtonsoft JSON.NET


You can deserialize your JSON into an ExpandoObject:

var converter = new ExpandoObjectConverter();dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(json, converter);

Which dynamically adds members to your object at runtime, and allows you to iterate over them as described in this answer:

foreach (var prop in obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)){   Console.WriteLine("Name: {0}, Value: {1}",prop.Name, prop.GetValue(obj,null));}

That way you can iterate over obj.message_tags to get the individual messages, and obtain all their details respectively.