当前位置:编程学习 > JS >>

jQuery遍历JSON对象

 

供以后用,直接看代码:

 

<script src="js/jquery-1.6.4.js" type="text/javascript"></script> 

 

<script type="text/javascript"> 

    $(document).ready(function() { 

        $("#Link").click(function() { 

        var objson = "[{Title:'Sjr',Content:'Library',summary:'summary'},{Title:'Sjr',Content:'Library',summary:[{sum0:'sum0'},{sum0:'sum1'},{sum0:'sum2'}]},{Title:'Sjr',Content:'Library',summary:[{sum0:'sum0'},{sum0:'sum1'},{sum0:'sum2'}]}]"; 

            var obj = eval(objson); 

            $(obj).each(function(index) { 

                var val = obj[index]; 

                if (typeof (val.summary) == "object") { 

                    $(val.summary).each(function(ind) { 

                        alert(val.Title + " " + val.Content + " " + val.summary[ind].sum0); 

                    }); 

                } else { 

                    alert(val.Title + " " + val.Content + " " + val.summary); 

                } 

            }); 

        }); 

    }); 

</script>   

作者 sjrhero

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,