首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

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

2012-10-29 
这种json对象里的多条数据如何进行操作呢??????????{basketFee:{fee:0.0,total:34.0},cart:{17:

这种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……

热点排行