【发布时间】:2017-01-18 13:01:39
【问题描述】:
尝试解析读取如下内容的 json 文件: [ { “名称”:“埃里克·韦斯特” “出生日期”:1994 年 8 月 29 日 } ] 需要解析文件,以便 mongodb 中的字段 Name 自动填充上面的 name 属性。
这是我想出的:
var url = "http://theurl";
if (Meteor.isServer) {
Meteor.methods({
jsonParse: function () {
this.unblock();
return Meteor.http.call("GET", url, data["Name"]);
}});}
//invoke the server method
if (Meteor.isClient) {
Meteor.call("jsonParse", function(error, results) {
console.log(results.content); //results.data should be a JSON object
});}
【问题讨论】:
-
你可以使用这个模块jsonfile来解析JSON文件
标签: javascript json parsing meteor