简体   繁体   中英

How to parse the javascript contents using nodejs

I am trying to parse the below mentioned javascript contents

<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>

But am not getting how to parse means i want to store the details like 'NM', 'PR', 'SL' into the variable using nodejs. My question is is it possible to parse this using nodejs? If it possible please tell me how to do this. Am new to nodejs. Please help me. Thanks in advance.

If you delete the "new Catalog" string, its a object. You can access it like catalog.Data.ID or catalog.Data.GC,

for example

var catalog={Data:{ID: 5, GC: 2}};
alert(catalog.Data.ID);

will show a message box with "5"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM