I have a simple JSON file which i need to get the value of a token, i have tried using SelectToken but the problem is that the name of the elements are dynamic. Here is my J
Try this:
string json = @"
{
""name"": ""testdata"",
""items"": {
""myItemName"": {
""located"": true
},
""myOtherItemName"": {
""located"": true
}
}
}";
JObject jsonObject = JObject.Parse(json);
foreach (JProperty prop in jsonObject.SelectToken("items"))
{
string name = prop.Name;
bool value = (bool)prop.Value.SelectToken("located");
Console.WriteLine(name + " = " + value);
}
Output:
myItemName = True
myOtherItemName = True