当前位置: 代码迷 >> Ajax >> 这种json对象里的多条数据怎么进行操作呢?
  详细解决方案

这种json对象里的多条数据怎么进行操作呢?

热度:312   发布时间:2012-10-29 10:03:53.0
这种json对象里的多条数据如何进行操作呢??????????
{
"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}
}

}

问题就在于cart下面的多条记录如何获取呢,试了很多办法都行不通,我是把map对象转成的json,所以会出现cart下的数字对应记录的情况,求各位牛人指教啊!!!!!!!!!!折腾了好半天了

------解决方案--------------------
JScript code

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表达式
}

------解决方案--------------------
HTML code

<!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的对象了,当然可以直接点过去用。
探讨

HTML code

<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312" />
<title></title>
</head>
<body>
<script>
var obj = {
"basket……
  相关解决方案