日期:2014-05-16  浏览次数:20302 次

Jquery遍历Json数据的示例(源码)
<html>
<head>
   <title>sssssss</title>
     <script src="lib/jquery/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>

注意:<script src="lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>的位置!