时间:2021-05-26
本文实例采用案例分析的方法介绍了jquery遍历json对象的三种情况,供大家参考,具体内容如下
第一个案例:jquery 遍历json对象集合 常用示例
jsp中
$.ajax({ url: "${applicationScope.rootpath}common/getContractPage.html?userConId=${userConId}", type: "post", dataType:"json", data: {}, success: function (jsonText) { if(jsonText){ var status = jsonText.status; var msg = jsonText.msg; if(status == '500'){ //有异常的信息时 alert(msg); }else{ $.each(jsonText,function(i,item){ var pngPath = item[0]; var pngName = item[1]; }); } } } });jsonText的格式:
java中:
第二个案例: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>第三个案例:jquery中遍历读取json串中的对象
假设我们从服务器端获取如下的json串,其中包括数组。我们该如何遍历读取呢?
复制代码 代码如下:{"result":null,"rows":[{"caishen":"东","fushen":"西北","huajiazi":"甲子","id":1,"nayin":"大海水","shengmen":"南","simen":"北","wugui":"西","xishen":"东南","yanggui":"西南","yingui":"东北"},{"caishen":"东北","fushen":"北","huajiazi":"乙丑","id":2,"nayin":"大林木","shengmen":"西北","simen":"西南","wugui":"东南","xishen":"东","yanggui":"西","yingui":"南"},{"caishen":"西","fushen":"东","huajiazi":"丙寅","id":3,"nayin":"石榴木","shengmen":"北","simen":"西北","wugui":"南","xishen":"东南","yanggui":"东北","yingui":"西南"}],"total":3}
使用.each难度太高,直接js读取吧
通过如上的方式就能获取json串的json对象并进行输出。
为大家分享这么多的案例,就是想帮助大家掌握jquery遍历json对象集合的方法,真正理解,希望这篇文章可以帮助到大家。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了jQuery实现简单复制json对象和json对象集合操作。分享给大家供大家参考,具体如下:/jquery/2.0.0/jquery.min.js
$.each:该方法用于遍历任何集合,包括数组和对象$(selector).each:该方法用于遍历Jquery对象语法:$.each(obj,callback
本文实例讲述了JS遍历json和JQuery遍历json操作。分享给大家供大家参考,具体如下:json遍历demodatavarjson={"test1":"d
1、遍历json对象的属性//定义json对象varperson={name:'zhangsan',pass:'123',fn:function(){alert
jquery获取除某指定对象外的其他对象.not()遍历方法从匹配元素集合中移除元素:not()选择器选取除了指定元素以外的所有元素。listitem1list