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