【问题标题】:Read a external json file in Neutralino app在 Neutralino 应用程序中读取外部 json 文件
【发布时间】:2020-08-18 14:14:37
【问题描述】:

如何读取外部 json 文件来填充我的 HTML? 我阅读了文档并看到“filesystem.readFile(字符串文件名,函数成功(数据),函数错误)”,但我不知道如何设置读取文件或放置文件的正确文件夹是什么。

【问题讨论】:

  • 我管理,将 json 更改为 js。我认为中立人暂时不解析 json。

标签: json neutralinojs


【解决方案1】:

文档中的此代码打印 json 文件中的数据。考虑解析返回的 json。 注意:该函数应始终是“异步”函数,否则将不起作用。

async function readMyjsonFile(){
    let response = await Neutralino.filesystem.readFile({
        fileName: './myFile.json'
    });
    console.log(`Content: ${response.data}`);
}

【讨论】:

    【解决方案2】:

    如果你使用 jQuery,你可以使用jQuery.getJSON() (https://api.jquery.com/jquery.getjson/)。

    jQuery.getJSON('relativePath/myFile.json',function(data){
      //Do something with your json data
    }
    

    jQuery.getJSON('file:///absolutePath/myFile.json',function(data){
      //Do something with your json data
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 2011-11-25
      • 2010-12-01
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 2016-06-25
      相关资源
      最近更新 更多