I am trying to parse a json file using json.net. The file looks like this
{X:
{
Title:\"foo\",
xxxx:xxxx
}
}
{Y:
{ZZ:
{Title: \"
Try this Method I have written it after some unsuccessful tries:
private void Traverse(JToken token, TreeNode tn)
{
if (token is JProperty)
if (token.First is JValue)
tn.Nodes.Add(((JProperty)token).Name + ": " + ((JProperty)token).Value);
else
tn = tn.Nodes.Add(((JProperty)token).Name);
foreach (JToken token2 in token.Children())
Traverse(token2, tn);
}
You first have to pass it the complete JSON file like this:
TreeNode rooty= tvu.Nodes.Add("Rooty") // not the Indian bread,just Rooty, Ok?
JToken token = JToken.Parse(File.ReadAllText(<"Path to json file">));
Traverse(token, rooty);
Done, Bom you got this one: Oh no, I am not allowed to embed pictures. sad.