Loading local JSON file

前端 未结 23 2005
悲哀的现实
悲哀的现实 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:47

    json_str = String.raw`[{"name": "Jeeva"}, {"name": "Kumar"}]`;
    obj = JSON.parse(json_str);
    
    console.log(obj[0]["name"]);

    I did this for my cordova app, like I created a new javascript file for the JSON and pasted the JSON data into String.raw then parse it with JSON.parse

提交回复
热议问题