我正在尝试解析来自服务器的数据。虽然我正在处理一个有效的 JSON,但我总是得到JSON unexpected character error
.
请考虑以下代码:
var shows = $.parseJSON(fetchData('contentShows', this.id)); // Returns a valid JSON data
$.each(shows, function(index, value) {
console.log(value.id);
});
fetchData = function(dataRequest, id) {
var data = $.ajax({
url: '/shows.php',
type: 'GET',
dataType: 'json',
success: function(data) {
console.log(dataRequest);
console.log(data);
}
});
return data;
}
这是示例 JSON:
[
{"shows":[],"spool":"/home","name":"Test Name","id":2}
]