www.1862.net > jquEry 如何遍历这样的json

jquEry 如何遍历这样的json

设置:var obj为你要遍历的json对象 $(obj).each(function(index) { var val = obj[index]; if (typeof (val.menus) == "object") { $(val.menus).each(function(ind) { alert(“销售” + val.menus[ind].menu_name); }); } else { error(); }

这和各浏览器的Map键名的遍历方法相关,jquery只不过是包装了一下 for (key in obj)。 解决方法为将键名放入的数组,通过遍历数组的方式就不会有问题了。 var a = []; $.each(obj, function(key, val) { a[a.length] = key; }); a.sort(); $.eac...

alert($(this).nidString);或者alert(list[i].nidString);有试过吗?

$.ajax({ url: "/xxxx/xxxx", type: "post", dataType: "json", success: function (datas) { var data = datas.data; if (data.length > 0) { content += '' for (var i = 0; i < data.length; i++) { content += ''; content += ''; content +...

var r= { "data": [ { "Count": "2", "HousesName": "归墅", "Price": "1", "AddressXy": "104.047791,30.69207" }, { "Count": "1", "HousesName": "思源", "Price": "100", "AddressXy": "104.167127,30.591898" } ]}var ss = $.parseJSON(r);...

我也看烦了,看着似乎有点明白,但又不怎么明白,先把代码写出来,再说说你这个json 代码如下: $.each(h, function () {//h就是你的json了 var h1 = this; alert("a:" + h1.a); $.each(h1.a1, function () { var h2 = this; alert("a2:" + h2.a...

var str='{"flag":false,"input_find_user":null,"map":{"MOBILE":"1","QUESTION":"1","userPhone":"189****2300","TOKEN":"1"}}'; var obj=eval("("+str+")"); //alert(obj.map.MOBILE); $.each(obj.map,function(n,value) { document.write(n+...

写成这样不就行了吗? cfg=[ {'2':{'title':'title2','name':'name2'}}, {'1':{'title':'title1','name':'name1'}}, {'4':{'title':'title4','name':'name4'}}, {'3':{'title':'title3','name':'name3'}} ]

var list;//ajax 异步从后台取回的json [{id:1},{id:2}]for(var i=0;i

var obj = {"id": 1, "name":"张三"}; for(var key in obj) { alert("Key是:" + key); alert("对应的值是:" + obj[key]); }

网站地图

All rights reserved Powered by www.1862.net

copyright ©right 2010-2021。
www.1862.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com