html - Parsing the Javascript content -


i have javascript code text, after parsing html file, , want "currencycode":"eur" out of strings, eur value, way can achieve it? regex ? thank

    $(document).ready(function() {     $('#book-simple').prepend('<div id="spinnercontainer" style="color: #224477;margin:5px 0 15px;text-align:center;"><img src="/img/spinner2.gif" />&nbsp;cargando pol&iacute;ticas...</div>')     $.post(         'bridget.php', {             f: 'policies',             h: '010',             d: '[{"rateplanid":"bar","rateplancode":"bar-sa","rateplantype":"bar","roomtypecode":"wstd","expiredate":"2014-03-22","effectivedate":"2014-03-21","sources":[{"ratesource":"bar","expiredate":"2014-03-21","effectivedate":"2014-03-21","amountaftertax":"230.0","amountbeforetax":"230.0","currencycode":"eur","discount":null}]},{"rateplanid":"388","rateplancode":"388-sa","rateplantype":"ofe","roomtypecode":"wstd","expiredate":"2014-03-22","effectivedate":"2014-03-21","sources":[{"ratesource":"bar","expiredate":"2014-03-21","effectivedate":"2014-03-21","amountaftertax":"230.0","amountbeforetax":"230.0","currencycode":"eur","discount":{"type":"dto","percent":"10.0"}}]},{"rateplanid":"bar","rateplancode":"bar-sa","discount":null}]}]',             l: 'fr_fr'         }, function(d) {  string content = html.documentnode.outerhtml 

this content variable has javascript code inside, wish use regex currencycode: eur

this valid json string.

i don't know how ended data looping through name , value of input fields or that... anyways.

the best way in javascript make string value of 'd' key in object valid json string , have appropriate element.

to make valid json string have remove 2 last characters '}]' since not match in string.

to make this, best way fix code produces string if can't here simple ugly way :

var incorrectstring = '[{"rateplanid":"bar","rateplancode":"bar-sa","rateplantype":"bar","roomtypecode":"wstd","expiredate":"2014-03-22","effectivedate":"2014-03-21","sources":[{"ratesource":"bar","expiredate":"2014-03-21","effectivedate":"2014-03-21","amountaftertax":"230.0","amountbeforetax":"230.0","currencycode":"eur","discount":null}]},{"rateplanid":"388","rateplancode":"388-sa","rateplantype":"ofe","roomtypecode":"wstd","expiredate":"2014-03-22","effectivedate":"2014-03-21","sources":[{"ratesource":"bar","expiredate":"2014-03-21","effectivedate":"2014-03-21","amountaftertax":"230.0","amountbeforetax":"230.0","currencycode":"eur","discount":{"type":"dto","percent":"10.0"}}]},{"rateplanid":"bar","rateplancode":"bar-sa","discount":null}]}]'  var correctedstring = incorrectstring.substring(0, incorrectstring.length - 2); 

then trivial :

var rateobject = json.parse(correctedstring)  var currencycode = rateobject[0].sources[0].currencycode 

the way built makes me feel reading bit on javascript , json thing you. see javascript objects , json.org


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -