I have JSON reply and i need to grab "Id" from it. I attempted 2 variations of the code below
using (JsonDocument document = JsonDocument.Parse(jsonstring))
{
JsonElement root = document.RootElement;
JsonElement resultsElement = root.GetProperty("Result");
List<string> names = new List<string>();
foreach (var result in resultsElement.EnumerateObject())
{
if (result.Value.TryGetProperty("Id", out resultsElement))
{
names.Add(resultsElement.GetString());
}
}
}
The requested operation requires an element of type 'Object', but the target element has type 'Number'.
adjusted EnumerateObject to Enumerate Array but i still get the same error with 'Array' - 'Object' instead of 'Object' - 'Array'
the JSON reply has this format:
{
"code":1,
"result":{
"Id":1,
"Name":"name"
}
}
I can't seem to be able to grab the specific Id using the bove method.
resultproperty that holds another object