Jquery遍历Json数据的方法

<html> <head> <title>jQuery遍历json</title> <script src="https://www.jb51.net/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> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjjjs.html