I am trying to deserialize this JSON string to different objects in C# using Newtonsoft.Json
{"apple":{"title":"apple","color":"red"},"banana":{"title":"banana","color":"yellow"}}
Note "apple" and "banana" in this example are dynamic values, so it's very well possible that suddenly it's called something others, e.g. ananas.
Now what I'm trying to do is deserialize this JSON string in a way that I can do a foreach loop through all the objects (Apple, Banana, ...) to read the value of the color
field.
But apparently I'm doing something wrong, this is my code.
dynamic d = JObject.Parse(jsonString);
foreach (dynamic e in d)
{
Console.WriteLine(e.title);
}
Does anyone know why this does not work like this?