1

I have a context menu which has menu items and sub menu items. A menu can have zero or more sub menu items.I need to map my menu object to a json object as follows. How can I do it?

            var commonMenuItems = [
              {
                  Menu: "Print",
                  Caption: "Print"


                  },
                  SubMenuItems: [
                    {
                        SubMenuItemName: "PrintSelected",
                        SubMenuItemDisplayName: "Print Selected",

                    },
                    {
                        SubMenuItemName: "PrintAll",
                        SubMenuItemDisplayName: "Print All",

                    }
                ]
              }

        ];

I want to map commonMenuItems array to items json object items programatically.

  items: {
                "Print": {"name": "Print"
                  "items":{
                       "PrintSelected": {"name": "Print Selected"},
                       "PrintAll": {"name": "Print All"},
                  }
}
1
  • I am looking at pure jquery answer. No Server side code involved Commented Nov 22, 2012 at 12:58

2 Answers 2

1

You can use JsonSerializer. There are many available.JSON.NET and ServiceStack.NET serializers are better options but I recommend you ServiceStack Serializer from NuGet Package.It is the fastest serializer on the planet.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming that you are returning commonMenuItems at client then converting it to javascript array var commonMenuItems = datagotfromserver; then to convert it to json you can simply use var items = JSON.stringify(commonMenuItems);.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.