从淘宝数据魔方抓取来的行情简报,json格式如下:
Js代码
- [[{"f1":"11","f3":"电脑硬件\/显示器\/电脑周边","f4":0.0131,"f5":23}], [{"f0":"2011-01-17","f1":20982935,"f2":47494},{"f0":"2011-01-18","f1":20482101,"f2":46403},{"f0":"2011-01-19","f1":20750121,"f2":44120},{"f0":"2011-01-20","f1":19114310,"f2":39529},{"f0":"2011-01-21","f1":18250333,"f2":36348},{"f0":"2011-01-22","f1":15330054,"f2":30043},{"f0":"2011-01-23","f1":12741582,"f2":27476}]]
[[{"f1":"11","f3":"电脑硬件\/显示器\/电脑周边","f4":0.0131,"f5":23}], [{"f0":"2011-01-17","f1":20982935,"f2":47494},{"f0":"2011-01-18","f1":20482101,"f2":46403},{"f0":"2011-01-19","f1":20750121,"f2":44120},{"f0":"2011-01-20","f1":19114310,"f2":39529},{"f0":"2011-01-21","f1":18250333,"f2":36348},{"f0":"2011-01-22","f1":15330054,"f2":30043},{"f0":"2011-01-23","f1":12741582,"f2":27476}]]
猜想是二维json吧,就如同二维数组一样的.实际应用中都是比较简单的json格式.解法如下:
Js代码
- <!-- power by ouou168.taobao.com -->
- <script type="text/javascript">
- var photoJson = [[{"f1":"11","f3":"电脑硬件\/显示器\/电脑周边","f4":0.0131,"f5":23}], [{"f0":"2011-01-17","f1":20982935,"f2":47494},{"f0":"2011-01-18","f1":20482101,"f2":46403},{"f0":"2011-01-19","f1":20750121,"f2":44120},{"f0":"2011-01-20","f1":19114310,"f2":39529},{"f0":"2011-01-21","f1":18250333,"f2":36348},{"f0":"2011-01-22","f1":15330054,"f2":30043},{"f0":"2011-01-23","f1":12741582,"f2":27476}]];
- document.write('行业类别:'+photoJson[0][0].f3+'<br />');
- document.write('行业排名:'+photoJson[0][0].f5+' '+'市场份额:'+photoJson[0][0].f4*100+'%<br />');
- for(i=0;i<photoJson[1].length;i++)
- {
- document.write(photoJson[1][i].f0+'销售金额:'+photoJson[1][i].f1+', 成交人数:'+photoJson[1][i].f2+'<br>');
- }
- </script>