rtdp.net
当前位置:首页 >> 怎样用For in 遍历一个函数里面 json 里的数组,就... >>

怎样用For in 遍历一个函数里面 json 里的数组,就...

for(var key in jsonObj) { documen.writeln(key+":"+jsonObj[key].toString()); }

最少你说下语言吧,都不说下语言怎么回答? 如果是js,数组直接for循环,然后如果是json对象,而你不知道key的话,采用 for(var i in json){ console.log('key:' + i +";value:" + json[i]); }

function fn(){ this.aa = "obj1"; this.bb = "obj2";}var json = {"aa":"json1","bb":"json2"};var obj = new fn();var radio = document.getElementById("radio"); console.log("-------------json----------------");for(var key in json){ ...

for(var i in Test){ var currentObject = Test[i] } 可以这遍历 不过你要判断currentObject类型

var typeArr = new Array();for(var i = 0;i

如果是js,数组直接for循环,然后如果是json对象,而你不知道key的话,采用 for(var i in json){ console.log('key:' + i +";value:" + json[i]); }

var myObj = { "name":"网站", "num":3, "sites":[ "Google", "Runoob", "Taobao" ] }; for (i in myObj.sites) { x += myObj.sites[i] + ""; } 或者 for (i = 0; i < myObj.sites.length; i++) { x += myObj.sites[i] + ""; }

jq框架下,给个示例,仅供参考: var objs = $.parseJSON('[{"name":"aaa","age":"22"},{"name":"bbb","age":"33"}]');var str = '';$.each(objs, function(k, obj){ str += obj.name + ' is ' + obj.age + "\n";});alert(str);

例如数据库里面的json字符串是这样的 ? 1 2 3 4 5 var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]'; var xqo = eval('(' + str + ')'); for(var i in xqo){ alert(xqo[i].name); } 上面的是...

var origin = [{"first_id":1,"first_name":"中学","second_id":"1-1","second_name":"一年级","third_id":"1-1-1","third_name":"一年级一班","people":10,"age":10,"parent":5},{"first_id":1,"first_name":"中学","second_id":"1-1","second_...

网站首页 | 网站地图
All rights reserved Powered by www.rtdp.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com