日期:2014-05-16 浏览次数:20708 次
var data = {
"basketFee":{"fee":0.0,"total":34.0},
"cart":{
"17":{"amount":18,"categoryName":"经典主食","id":17,"name":"tes1t商品","price":0.0,"subtotal":0.0},
"13":{"amount":34,"categoryName":"正餐","id":13,"name":"商品名称3","price":1.0,"subtotal":34.0},
"18":{"amount":14,"categoryName":"经典主食","id":18,"name":"test2商品","price":0.0,"subtotal":0.0}
}
}
for(var name in data.cart)
{
alert(name + "=" + data.cart[name]);//不确定的属性使用in表达式
}
------解决方案--------------------
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>        
    </head>
    <body>
        <script>
            var obj = {
                "basketFee":{"fee":0.0,"total":34.0},
                "cart":{
                    "17":{"amount":18,"categoryName":"经典主食","id":17,"name":"tes1t商品","price":0.0,"subtotal":0.0},
                    "13":{"amount":34,"categoryName":"正餐","id":13,"name":"商品名称3","price":1.0,"subtotal":34.0},
                    "18":{"amount":14,"categoryName":"经典主食","id":18,"name":"test2商品","price":0.0,"subtotal":0.0}
                }
            };
            alert( obj.cart[17].categoryName )
        </script>
    </body>
</html>
------解决方案--------------------
+1本来就是json的对象了,当然可以直接点过去用。