我的 some.json
文件与我的前端 JavaScript
文件位于同一目录中。读取 .json
文件的正确方法是什么,那么我可以这样做:
obj = JSON.parse(json);
最佳答案
XHR。如果您使用 jQuery,则只需使用:
$.getJSON('path/to/json', function(obj) {
});
和 XHR:
var req = new XMLHttpRequest();
req.open("GET", "file.json", true);
req.onreadystatechange = function(){
obj = JSON.parse(req.responseText);
}; // la fonction de prise en charge
req.send(null);
关于javascript - 读取 .json 文件并解析其数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25590797/