How can I open a JSON file in JavaScript without jQuery?

前端 未结 4 585
清歌不尽
清歌不尽 2020-11-27 15:20

I am writing some code in JavaScript. In this code i want to read a json file. This file will be loaded from an URL.

How can I get the contains of this JSON file in

4条回答
  •  执念已碎
    2020-11-27 15:35

    JSON has nothing to do with jQuery.

    There is nothing wrong with the code you have now.


    To store the variable mainStore, it is a variable in that json.

    You should store that json to a variable:

    var myJSON = {"mainStore":[{vehicle:'1',description:'nothing to say'},{vehicle:'2',description:'nothing to say'},{vehicle:'3',description:'nothing to say'}]};
    
    var mainStore = myJSON.mainStore;
    
    //.. rest of your code.
    

提交回复
热议问题