https://stackoverflow.com/questions/20318261/dynamic-object-with-dollar-on-string
https://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object
https://stackoverflow.com/questions/47507667/deserialize-json-with-variable-property-names
https://www.jerriepelser.com/blog/deserialize-different-json-object-same-class/
dynamic stuff = JsonConvert.DeserializeObject<dynamic>("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");
string name = stuff.Name;
string address = stuff.Address.City;
foreach (JProperty jproperty in stuff)
{
Console.WriteLine("jproperty.Name = {0}", jproperty.Name);
}
dynamic d = stuff.Address;
foreach (JProperty jproperty in d)
{
Console.WriteLine("d.Name = {0}", jproperty.Name);
}
Comments
Post a Comment