private void VisualizeJsonTree(XJToken tree) { AddNode(tvJson.Nodes, tree); TreeNode node = GetRootNode(); node.Expand(); tvJson.SelectedNode = node; }
private void mnuCopyValue_Click(object sender, EventArgs e) { var node = tvJson.SelectedNode; if (node?.Tag != null) { XJToken obj = node.Tag as XJToken; SetClipboard(obj.ValueString()); } else { SetClipboard(""); } }
private void AddNode(TreeNodeCollection nodes, XJToken jsonObject) { TreeNode newNode = new TreeNode(); nodes.Add(newNode); newNode.Text = GetShowText(jsonObject); newNode.Tag = jsonObject; newNode.ImageIndex = (int)jsonObject.JsonType; newNode.SelectedImageIndex = newNode.ImageIndex; if (jsonObject.Children != null) { foreach (XJToken field in jsonObject.Children) { AddNode(newNode.Nodes, field); } } }
private string GetShowText(XJToken jsonObject) { string txt = jsonObject.Name; if (jsonObject.IsRoot) { txt = "JSON"; } switch (jsonObject.JsonType) { case JsonType.Array: txt += " : [" + jsonObject.Children.Count + "]"; break; case JsonType.Object: txt += " : {" + jsonObject.Children.Count + "}"; break; default: txt += " : " + jsonObject.ValueString(); break; } return(txt); }