长度和迭代JSON对象

时间:2014-11-20 13:27:42

标签: javascript json

我正在通过url获取json并且我已经解析了它。结果json是

[{                                                                    
"id": "675285"                                                        
,"t" : "BBG"                                                          
,"e" : "ASX"                                                          
,"l" : "0.645"                                                        
,"l_fix" : "0.645"                                                    
,"l_cur" : "A$0.64"                                                   
,"s": "0"                                                             
,"ltt":"4:10PM GMT+11"                                                
,"lt" : "Nov 20, 4:10PM GMT+11"                                       
,"lt_dts" : "2014-11-20T16:10:58Z"                                    
,"c" : "+0.010"                                                       
,"c_fix" : "0.010"                                                    
,"cp" : "1.57"                                                        
,"cp_fix" : "1.575"                                                   
,"ccol" : "chg"                                                       
,"pcls_fix" : "0.635"                                                 
}                                                                     
,{                                                                    
"id": "690577"                                                        
,"t" : "PBG"                                                          
,"e" : "ASX"                                                          
,"l" : "0.515"                                                        
,"l_fix" : "0.515"                                                    
,"l_cur" : "A$0.52"                                                   
,"s": "0"                                                             
,"ltt":"4:11PM GMT+11"                                                
,"lt" : "Nov 20, 4:11PM GMT+11"                                       
,"lt_dts" : "2014-11-20T16:11:05Z"                                    
,"c" : "0.000"                                                        
,"c_fix" : "0.000"                                                    
,"cp" : "0.00"                                                        
,"cp_fix" : "0.000"                                                   
,"ccol" : "chb"                                                       
,"pcls_fix" : "0.515"                                                 
}]

这个json有什么问题吗?我无法得到这个json的长度(即2)并且在获得价值方面存在问题。

1 个答案:

答案 0 :(得分:-1)

实际上,json还可以。 这适用于你的json。

var a = JSON.parse('[{"id": "675285","t" : "BBG","e" : "ASX","l" : "0.645","l_fix" : "0.645","l_cur" : "A$0.64","s": "0","ltt":"4:10PM GMT+11","lt" : "Nov 20, 4:10PM GMT+11","lt_dts" : "2014-11-20T16:10:58Z","c" : "+0.010","c_fix" : "0.010","cp" : "1.57","cp_fix" : "1.575","ccol" : "chg","pcls_fix" : "0.635"},{"id": "690577","t" : "PBG","e" : "ASX","l" : "0.515","l_fix" : "0.515","l_cur" : "A$0.52","s": "0","ltt":"4:11PM GMT+11","lt" : "Nov 20, 4:11PM GMT+11","lt_dts" : "2014-11-20T16:11:05Z","c" : "0.000","c_fix" : "0.000","cp" : "0.00","cp_fix" : "0.000","ccol" : "chb","pcls_fix" : "0.515"}]');
alert(a.length);