kttq.net
当前位置:首页 >> js 遍历json kEy >>

js 遍历json kEy

将json转化为数组, 然后进行for循环, 如: var arr = 数组; for(var i=0;i

Js代码 getJson('age'); function getJson(key){ var jsonObj={"name":"傅红雪","age":"24","profession":"刺客"}; //1、使用eval方法 var eValue=eval('jsonObj.'+key); alert(eValue); //2、遍历Json串获取其属性 for(var item in jsonObj){ i...

var obj = {};for(var k in obj) { //遍历对象,k即为key,obj[k]为当前k对应的值 console.log(obj[k]);}

var obj = {"a": "aa","b": "bb"}; for(var o in obj){ console.log('Key is ' + o + ';value is ' + obj[o]); }

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

var json = {a: "aaaa",v: 'vvvv'}; for(var k in json) { console.log('key is ' + k); console.log('value is' + json[k]); }

var obj = { "a": 1, "b": 2, "c": "ssss"};for(var o in obj) { console.log("key: " + o + "-------value: "+ obj[o]);}

var list = {"id":1,"key":101,"value":"value"};var str = "";for(var name in list){ str+=name+"="+list[name].toString();}alert(str);

var json = {a : 1,b : 2}for( i in json){console.log(i);console.log(json[i]);}

json是种常用数据传输格式,js怎么解析json格式的数据呢,请参阅下面的代码: [html] view plain copy print? var data = '{"return_code":0,"return_message":"success","data":{"data":[{"id":"1","question":"公主令牌在哪交?"},{"id":"2","...

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