本文实例讲述了JS 遍历 json 和 JQuery 遍历json操作。分享给大家供大家参考,具体如下:

json 遍历
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>demo data</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<script>
var json = {
"test1" : "data1",
test2 : "data2"
};
//jquery 其中i 是键名 v 是键值
$.each(json,function(i,v){
console.log(i + " =============== " + v);
})
//javascript 遍历 i 是键名 json[i] 是键值
var json = {
"test1" : "data1",
test2 : "data2"
};
for(i in json)
{
console.log(i + " ======================== " + json[i]);
}
</script>
</body>
</html>