日期:2014-05-16  浏览次数:20488 次

求json to array并显示array!!!
昨天问了关于以下json遍历的问题,遍历会了,但如何把其转成数组并取值不会,还得麻烦朋友们!!!
到时我就可以通过相应id找到相应的name等!!!

var carData={"'34'":{"name":"A \u963f\u65af\u987f\u00b7\u9a6c\u4e01"
,"brand":{"'61'":{"name":"\u963f\u65af\u987f\u00b7\u9a6c\u4e01"
,"pserise":{"'298'":{"name":"Rapide","import":"2","model":{"'11563'":"Rapide 6.0L S","'5290'":"Rapide 6.0L"}},"'299'":{"name":"V12 Vantage","import":"2"
,"model":{"'11446'":"V12 Vantage 6.0L S","'8947'":"V12 Vantage 6.0 Roadster","'5291'":"V12 Vantage 6.0 Manual Coupe"}},"'629'":{"name":"V12 Zagato","import":"2"
,"model":{"'9037'":"V12 Zagato 6.0L"}},"'300'":{"name":"V8 Vantage","import":"2"
,"model":{"'5292'":"V8 Vantage 4.7 S Coupe","'5293'":"V8 Vantage 4.7 S Roadster","'5294'":"V8 Vantage 4.7 Sportshift Coupe","'5295'":"V8 Vantage 4.7 Sportshift Roadster"}},"'643'":{"name":"Vanquish","import":"2","model":{"'9057'":"Vanquish 6.0 \u57fa\u672c\u578b"}},"'301'":{"name":"Virage","import":"2"
,"model":{"'5301'":"Virage 6.0 Coupe","'5302'":"Virage 6.0 Volante"}},
"'302'":{"name":"\u963f\u65af\u987f\u9a6c\u4e01DB9","import":"2"
,"model":{"'10244'":"\u963f\u65af\u987f\u9a6c\u4e01DB9 6.0L Coupe"}}
,"'303'":{"name":"\u963f\u65af\u987f\u9a6c\u4e01DBS","import":"2"
,"model":{"'5311'":"\u963f\u65af\u987f\u9a6c\u4e01DBS 6.0 Touchtronic Coupe","'5312'":"\u963f\u65af\u987f\u9a6c\u4e01DBS 6.0 Manual Volante","'5313'":"\u963f\u65af\u987f\u9a6c\u4e01DBS 6.0 Touchtronic Volante","'5314'":"\u963f\u65af\u987f\u9a6c\u4e01DBS 6.0 Manual Coupe"}}}}}}}

------解决方案--------------------
你说的是key-value形式的存取?
参考

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script type="text/javascript">
var data = [{"a":"xx","b":"xx","动态值":"xx"},{"a":"xx","b":"xx"}];
for (var i in data){
for (var j in data[i]){
alert(j);
alert(data[i][j]);
}
}
</script>
</body>
</html>

------解决方案--------------------