未捕获的语法错误:JSON.parse(<;anonymous>;)位置0处的JSON中出现意外标记d

未捕获的语法错误:JSON.parse(<;anonymous>;)位置0处的JSON中出现意外标记d,json,Json,几个小时以来,我一直在疯狂地尝试使用json.parse从外部获取和显示json数据,但下面出现了这个错误 未捕获的语法错误:JSON中位置0处出现意外标记d 在JSON.parse()处 在index.html:10 以下是我迄今为止的代码和努力。有人能帮我解决这个问题吗。我会很感激的 $.getJSON是异步的,因此您应该执行以下操作: $.getJSON("data.json", function(json) { console.log(json); // this will s

几个小时以来,我一直在疯狂地尝试使用json.parse从外部获取和显示json数据,但下面出现了这个错误

未捕获的语法错误:JSON中位置0处出现意外标记d 在JSON.parse()处 在index.html:10

以下是我迄今为止的代码和努力。有人能帮我解决这个问题吗。我会很感激的


$.getJSON是异步的,因此您应该执行以下操作:

$.getJSON("data.json", function(json) {
    console.log(json); // this will show the info it in firebug console
});

以下是一个可能对您有所帮助的示例:

function loadJSON() {
  var http = new XMLHttpRequest();
  http.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var data=JSON.stringify(this.responseText);
        data=JSON.parse(data);
        console.log(data);
    }
  };
  http.open("GET", "data.json", true);
  http.send();
}
loadJSON()

您不能使用
JONS.parse
从服务器获取数据。@FerhadOthman。请看下面的例子,我该怎么做
$.getJSON("data.json", function(json) {
    console.log(json); // this will show the info it in firebug console
});
function loadJSON() {
  var http = new XMLHttpRequest();
  http.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var data=JSON.stringify(this.responseText);
        data=JSON.parse(data);
        console.log(data);
    }
  };
  http.open("GET", "data.json", true);
  http.send();
}
loadJSON()