我正在尝试解析下面提到的javascript内容
<script type="text/javascript">
//<![CDATA[
var catalog = new Catalog({"Data":[{'ID':'rsafl502','GC':'RSAFL502','CT':49,'SU':1875,'DC':'Smoke','NM':'Watery Faux Leather Purse','PR':'Reg $56.00','SL':'$15.00','oSL':true,'RT':'40','CL':[{'E':'Black','L':'Black','V':['#000000']},{'E':'Smoke','L':'Smoke','V':['#383E50']}],'SZ':[{'E':'One Size','L':'One Size'}],'SC':''}
,{'ID':'rsavp500m','GC':'RSAVP500M','CT':49,'SU':1029,'DC':'Navy','NM':'Medium Emergency Bag','PR':'Reg $24.00','SL':'$15.00','oSL':true,'RT':'50','CL':[{'E':'Black','L':'Black','V':['#000000']},{'E':'Navy','L':'Navy','V':['#07194D']},{'E':'Crucian Blue','L':'Crucian Blue','V':['#00b4ee']}],'SZ':[{'E':'M','L':'M'}],'SC':''}
]});
//]]>
</script>
但是我没有得到如何解析意味着我想使用nodejs将'NM','PR','SL'等细节存储到变量中。我的问题是是否可以使用nodejs解析它?如果有可能请告诉我如何做到这一点。我是nodejs的新手。请帮我。提前谢谢。
答案 0 :(得分:1)
如果删除“new Catalog”字符串,则为其对象。您可以像catalog.Data.ID或catalog.Data.GC,
那样访问它例如
var catalog={Data:{ID: 5, GC: 2}};
alert(catalog.Data.ID);
将显示一个带有“5”的消息框