Loading local JSON file

前端 未结 23 1597
悲哀的现实
悲哀的现实 2020-11-22 01:28

I\'m trying to load a local JSON file but it won\'t work. Here is my JavaScript code (using jQuery):

var json = $.getJSON("test.json");
var data = e         


        
23条回答
  •  一生所求
    2020-11-22 01:49

    What I did was editing the JSON file little bit.

    myfile.json => myfile.js

    In the JSON file, (make it a JS variable)

    {name: "Whatever"} => var x = {name: "Whatever"}

    At the end,

    export default x;

    Then,

    import JsonObj from './myfile.js';

提交回复
热议问题