How to pass a javascript object that contains strings with quotes from node.js to the browser?

前端 未结 2 736
野趣味
野趣味 2021-01-24 10:03

I have a node/express application and want to pass a javascript object to the browser. Currently I do this by JSON.stringifying the object and printing it into the

2条回答
  •  耶瑟儿~
    2021-01-24 10:28

    In your template, remove the JSON.parse.

    var myObjectInBrowser = {{{myObjectString}}};
    

    If you've already encoded the data as JSON, this is directly parseable by the JavaScript engine. If you add another JSON.parse to that, you are double-parsing.

提交回复
热议问题