Skip to content

How we create the dynamic menus using JSON and jquery

ankit srivastava

Asked Sep 22, 2017, 12:51 AM EDT1 answer
Share
LinkedInX
I want to create the dynamic menus using jquery and json.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    C#
    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; }
    
    
        }
    }
    0