Sorry for the nube-like question, but having been retired for sometime I find myself forgetting some things.
Given this sample json string:
{
"range": [
{ "num": 0 },
{ "num": 1 },
{ "num": 2 },
{ "num": 3 },
{ "num": 4 },
{ "num": 5 },
{ "num": 6 },
{ "num": 7 },
{ "num": 8 },
{ "num": 9 }
],
"friends": [
{
"id": 0,
"name": "Christian Cruz"
},
{
"id": 1,
"name": "Hunter Moon"
},
{
"id": 2,
"name": "Holden Gentry"
}
]
}
I would like to be able to read the root value ("range" and "friends" in this case) for each line in the data, then parse the remaining values.
void Main()
{
var json = File.ReadAllText(@"c:\data\sample.json");
JObject obj = JObject.Parse(json);
foreach(JProperty child in obj.Children())
{
}
}
Where I bogged down is as I iterate through the children collection (foreach(JProperty child ...) I can read the items in the array (e.g. "num", "id" and "name") but I am unable to read the root values (e.g. "range" and "friends")
Any help you could lend an old man would be very much appreciated.
Nameproperty of eachchildshows the property's name as expected: dotnetfiddle.net/GvRsYe