从EJS到JS中的JSON对象的JSON [英] JSON from EJS to JSON object in JS
本文介绍了从EJS到JS中的JSON对象的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有Node.JS的EJS,并将JSON对象传递给它,但需要将其作为页面中的可用对象进行访问。我从这里得到了意外的令牌o错误:
I am using EJS with Node.JS, and am passing a JSON object into it, but need to have access to it as a usable object in the page. I am getting the unexpected token o error from this:
var initData=JSON.parse(<%-JSON.stringify(list)%>);
我不知道这里有什么问题。
I cant figure out whats wrong here.
这是渲染时文件中的样子:
This is what it looks like in the file when rendered:
var initData=JSON.parse([{"title":"South Hills Health System - University Health Center","adr":"200 Lothrop St,15213","coords":"40.441875,-79.960813","images":[],"tags":[],"_id":"51c0e9798384f40000000017"},{"title":"Bombay Food Market","adr":"4605 Centre Avenue, Pittsburgh, PA 15213, USA","coords":null,"images":[],"tags":["indian","groceries","ethnic","store"],"_id":"51c0519e02b7cbec73000002"}]);
推荐答案
试试这个:
var initData = JSON.parse('<%-JSON.stringify(list)%>');
OR:
var initData = <%-JSON.stringify(list)%>;
这篇关于从EJS到JS中的JSON对象的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文