【问题标题】:Reading JSON file in Meteor在 Meteor 中读取 JSON 文件
【发布时间】: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


【解决方案1】:

请重写你的代码

if (Meteor.isClient) {
Meteor.call("jsonParse", function(error, results) {
let result = JSON.parse(results.content); //results.data should be a JSON object
console.log(result);
});
}

你应该得到一个结果。您可以访问 result.Nameresult.DOB

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-25
    • 2023-04-07
    • 2015-11-19
    • 2016-10-15
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多