The example in this article describes the method of Jquery traversing Json data. Share it with everyone for your reference. The details are as follows:
<html> <head> <title>jQuery遍历json</title> <script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> </head> <script> var a = { "sys_bb": [ { "menu_name": "教务处", "menus": [ { "menu_name": "张明" }, { "menu_name": "王明" } ] }, { "menu_name": "办公室", "menus": [ { "menu_name": "刘处" }, { "menu_name": "小王" }, { "menu_name": "张三" } ] } ], "sys_cw": [ { "menu_name": "财务处", "menus": [ { "menu_name": "王虎" } ] } ] }; $(function () { $.each(a.sys_bb, function (i, n) { $("#Div").append(a.sys_bb[i].menu_name + "<br>"); $.each(a.sys_bb[i].menus, function (i, n) { $("#Div").append(" " + n.menu_name + "<br>"); }); }); $.each(a.sys_cw, function (i, n) { $("#Div").append(a.sys_cw[i].menu_name + "<br>"); $.each(a.sys_cw[i].menus, function (i, n) { $("#Div").append(" " + n.menu_name + "<br>") }); }); }); </script> <body> <div id="Div"> </div> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.