I want to create the dynamic menus using jquery and json.
How we create the dynamic menus using JSON and jquery
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
ankit srivastavaRank #8,839 · 215 pointsPosted Sep 22, 2017, 12:53 AM EDT
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace JsonCreator { class Program { static void Main(string[] args) { List<ParentNode> liNode = new List<ParentNode>(); for (int i = 0; i < 8; i++) { ParentNode node = new ParentNode(); if (i == 0) { node.IsChildExists = false; } else { node.IsChildExists = true; } node.NodeId = "P" + i.ToString(); node.NodeName = "ParentNode" + i.ToString(); node.NodeLink = "#"; List<Node> liChildNode = new List<Node>(); if (node.IsChildExists) { for (int i1 = 0; i1 < 8; i1++) { Node node1 = new Node(); node1.IsChildExists = false; node1.NodeId = "C" + i1.ToString(); node1.NodeName = "ChildParentNode" + i1.ToString(); node1.NodeLink = "#"; liChildNode.Add(node1); } } node.childNode = liChildNode; liNode.Add(node); } var data = Newtonsoft.Json.JsonConvert.SerializeObject(liNode); } } class ParentNode :Node { public List<Node> childNode { get; set; } } class Node { public string NodeId { get; set; } public string NodeName { get; set; } public string NodeLink { get; set; } public bool IsChildExists { get; set; } public int ParentId { get; set; } } }