二维json 遍历取值

原创 yinglsc 随笔 js 521阅读 2017-08-30 17:42:05 举报

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>111</title>

</head>

<body class="gray-bg">

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    var obj ={"total":2,"data":[{"cardDevices":[{"brand":"品牌1","id":"1","number":"21001","type":"ic","version":"1.0","window":{"$ref":"$.data[0]"}}],"id":"1","name":"1号窗口","number":"1001","operator":"张三","phone":"111111111","restaurant":"1号餐厅"},{"cardDevices":[{"brand":"品牌1","id":"2","number":"21002","type":"ic","version":"1.0","window":{"$ref":"$.data[1]"}}],"id":"2","name":"2号窗口","number":"1002","operator":"李四","phone":"12312312312","restaurant":"2号餐厅"}]}
    /*var newarr = obj.data;
    newarr.forEach(function(value,index){
        console.log(value.cardDevices[0].number)
    })*/
    for( i in obj){
        console.log('i',i);
                var val=obj[i];
                for( j in val){
                    //console.log('j',j);
                    console.log(val[j].cardDevices[0].number)
                }
            }
})
</script>

</body>
</html>

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复