我的代码访问属性:
var myArray = [{"td_stlmnt":"NN2015227","Heading":"NN2015227[02/12/2015]","td_scripcd":"514286","Order#":"1000000003042299","Trade#":"1124070","Time":"14:40:38","Security":"ASHIMASYN (514286)","Buy":"250","Sell":"0","Market Rate":"12.90","Brokerage":"12.50","Buy Value":"3237.5000","Sell Value":".0000","_":"","Ordr":"ASHIMASYNb","BDate":"20151202","Net Value":""},{"td_stlmnt":"NN2015227","Heading":"NN2015227[02/12/2015]","td_scripcd":"514286","Order#":"1000000003042299","Trade#":"1124072","Time":"14:40:38","Security":"ASHIMASYN (514286)","Buy":"250","Sell":"0","Market Rate":"12.90","Brokerage":"12.50","Buy Value":"3237.5000","Sell Value":".0000","_":"","Ordr":"ASHIMASYNb","BDate":"20151202","Net Value":""}];
alert(myArray[2].Order# );
<html>
<body>
</body>
</html>
获取JS错误未捕获语法错误:意外字符串 - &gt;警告 - 当我编码为.Order#时,如果我使用.Order则值未定义。 可能的解决办法是什么?
答案 0 :(得分:0)
您必须使用括号表示法:json[2]['Order#']
您不能在字符串中使用#
var myArray = [{"td_stlmnt":"NN2015227","Heading":"NN2015227[02/12/2015]","td_scripcd":"514286","Order#":"1000000003042299","Trade#":"1124070","Time":"14:40:38","Security":"ASHIMASYN (514286)","Buy":"250","Sell":"0","Market Rate":"12.90","Brokerage":"12.50","Buy Value":"3237.5000","Sell Value":".0000","_":"","Ordr":"ASHIMASYNb","BDate":"20151202","Net Value":""},{"td_stlmnt":"NN2015227","Heading":"NN2015227[02/12/2015]","td_scripcd":"514286","Order#":"1000000003042299","Trade#":"1124072","Time":"14:40:38","Security":"ASHIMASYN (514286)","Buy":"250","Sell":"0","Market Rate":"12.90","Brokerage":"12.50","Buy Value":"3237.5000","Sell Value":".0000","_":"","Ordr":"ASHIMASYNb","BDate":"20151202","Net Value":""}];
document.write(myArray[1]['Order#']);