【发布时间】:2014-02-25 12:26:44
【问题描述】:
我尝试使用 Meteor JS 访问 JSON 文件数据。但我无法访问它。谁能建议我做错了什么?
文件夹结构:
myapp project/lib folder - myfile.json
我的文件.json:
EJSONObj = {
"first": "John",
"last": "Doe",
"age": 39,
"sex": "M",
"salary": 70000,
"registered": true,
"favorites":
{
"color": "Blue",
"sport": "Soccer",
"food": "Spaghetti"
}
}
流星JS:
if (Meteor.isClient)
{
console.log("My JSON File data:"+EJSONObj.age);
}
错误是:
Uncaught ReferenceError: EJSONObj is not defined
【问题讨论】:
-
如果你将
myfile.json重命名为myfile.js,你可以让它以当前的方式工作。请参阅:stackoverflow.com/questions/15374066/… -
哦,好吧。但是在 Meteor 中使用 Json 文件有什么用?.@Akshat.
-
myfile.JSON不是 JSON 文件。它实际上是一个js文件。 JSON 文件中不能有 LVALUE。所以a = { ... }不是有效的 JSON。
标签: javascript json meteor