How to read an external local JSON file in JavaScript?

前端 未结 22 1949
醉酒成梦
醉酒成梦 2020-11-22 02:53

I have saved a JSON file in my local system and created a JavaScript file in order to read the JSON file and print data out. Here is the JSON file:

{"res         


        
22条回答
  •  不知归路
    2020-11-22 03:23

    Using the Fetch API is the easiest solution:

    fetch("test.json")
      .then(response => response.json())
      .then(json => console.log(json));
    

    It works perfect in Firefox, but in Chrome you have to customize security setting.

提交回复
热议问题