标签:
alert(index); => 0,1, 2, 3, 4alert(obj); =>{"id":"1","tagName":"apple"},{"id":"2","tagName":"orange"}...alert(obj.id); => 1, 2, 3, 4, 5alert(obj.tagName); => apple, orange, banana, watermelon, pineapple
}); =>第0项的tagName是apple 第1项的tagName是orange..................
alert(index)}) =>0 1 2 3 4 5 6 7 8
alert(value)
alert(this)}) =>9 8 7 6 5 4 3 2 1
var data=[{ "1" :{ "name" : "kc" , "status" :1}},{ "2" :{ "name" : "bc" , "status" :2}}]; 原生JS获取:
|
for
(
var
i=0;i<data.length;i++){
for
(
var
item
in
data[i]){
//{"1":{"name":"kc","status":1}},{"2":{"name":"bc","status":2}}
console.log(
item
);
//
key
1,2
console.log(data[i][item]);
//
value
{name: "kc", status: 1},{name: "bc", status: 2}
console.log(data[i][item].name);
//
kc bc 获取属性值
console.log(data[i][item].status);
//1 2 获取属性值
}
}
----------------------------------------------------------------------------------------------------------------------------------------
jquery获取
$.each(data,
function
(key,val){
console.log(key);
//索引
console.log(val);
//{"1":{"name":"kc","status":1}},{"2":{"name":"bc","status":2}}
$.each(val,
function
(key1,val1) {
console.log(key1);
//key 1,2
console.log(val1);
//value, {name: "kc", status: 1},{name: "bc", status: 2}
console.log(val1.name);
//属性值
});
})
alert(key); =>jim tom lileialert(value); =>11 12 13
json的的解析方法
json的解析方法共有两种:eval() 和 JSON.parse(),使用方法如下:
这样就把jsonData这个json格式的字符串转换成了JSON对象。
标签:
原文地址:http://www.cnblogs.com/xiabingbing/p/5000193.html