parsing - How can i JSON.stringify some JSON and place into html then parse it in nodejs server by JSON.parse -


i want stringify json first in html file using javascript place in html, after i'm parsing html using cheeriojs & request in nodejs , here want json json.parse() method, how can that.

here html code:

    <script type="text/javascript">     //stringify json      var nav = {                  component : "navbar",                 container_class : "div",                 menu_link_color: "blue",                 hover_color: "white"             }      var str = json.stringify(nav);      document.getelementbyid('edit').innerhtml=str;           </script> </head> <body> <div class="wp" id="edit">  </div> </body> </html> 

here nodejs code parse html stringified json:

var url = "http://localhost/test/test.html"; request(url,function(err,res,body){     var $ = cheerio.load(body);     $('.wp').filter(function(){         var navbar = $(this);         var navtext = navbar.text();         var textjson = json.parse(navtext);         console.log(textjson);     });     }) 

i have done job following these steps:

  • built json object in javascript
  • json.stringify() json object
  • place json string html , hide display
  • then have parse json string in nodejs using cheeriojs
  • in node server have json.parse() string , convert json object need html.

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -