[英]JSON.parse not erroring but not working
我正在基于ajax进行Web设计工作。 我的JSON.parse()函数有问题。 问题如下,我使用ajax在JSON数据库上执行get请求:
artist_list = $.ajax({
dataType: "json",
async: false,
method: "GET",
url: "/database/artists.json",
error: function (xhr) {
console.log("AJAX error:", xhr.status);
},
success: function(xhr, responseText) {
console.log("Ajax operation succseded the code was:", xhr.status);
console.log("This is the output", responseText);
response = responseText;
console.log("Parsing artist list");
JSON.parse(response);
console.log("Artist list parsed");
},
done: function(data, textStatus, jqXHR){
console.log("data:", data);
console.log("Response text",jqXHR.responseText);
}
})
responseText的控制台日志与我想要的JSON文件匹配,但是,当我通过for循环运行响应文本时,该日志按char返回JSON文件char:
artist_list = artist_list.responseText;
JSON.parse(artist_list);
console.log(artist_list);
for(var i = 0; i < 1; i++) {
console.log("generating artist,", i);
console.log("which is:", artist_list[i]);
index = parseInt(i);
index = new artist_lite(artist_list[i]);
artist_lite_dict.push(index);
}
控制台返回:
generating artist, 0
which is: {
由于我要传递的JSON对象的长度,该列表限制为一个。 JSON可以在这里找到https://github.com/Stephan-kashkarov/Collector/blob/master/main/database/artists.json以及用于测试目的的整个代码。
谢谢你的帮助! -斯蒂芬
您需要保存JSON.parse(artist_list);
的结果JSON.parse(artist_list);
变成一些变量 我想在您的代码中您想这样解决:
artist_list = JSON.parse(artist_list);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.