遍历json

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
</body>
</html>
<script>
    var json={width:100, height:100 , left:50, top:100}
    for( k  in  json)
    {
        console.log(k); //k是属性
        console.log(json[k]); //json[k]得到属性的值
        console.log(k+":"+json[k]);

    }
</script>

  注意:

  遍历json ,k 是属性, json[k]是属性的值

posted @ 2019-07-28 20:25  shanlu  阅读(154)  评论(0编辑  收藏  举报