我有以下代碼和輸出,並且我不能很好地解碼json數據上的任何錯誤。誰能幫我找到這個錯誤Jquery - Ajax:SyntaxError:JSON.parse:意外字符
CODE:
$.ajax({
'type': 'get',
'data': {},
'dataType': 'json',
'url': 'dashboard/data/'+type,
'complete': function(data) {
var top10Value = JSON.parse(data);
$.each(top10Value, function(key,value){
console.log(key+" -- "+value);
});
}
});
OUTPUT:
[{"name":"Bubble Witch Saga 2","impressions":10749},{"name":"Grinder","impressions":11284},{"name":"Loovoo","impressions":12336},{"name":"Injustice God Among Us","impressions":12786},{"name":"Bookmyshow","impressions":13182},{"name":"Angry Bird","impressions":15404},{"name":"Flipkart","impressions":16856},{"name":"CNN-IBN","impressions":17230},{"name":"Fore Square","impressions":17595},{"name":"NDTV","impressions":19542},{"name":"Whatsapp","impressions":19976}]
你不需要使用'JSON.parse' - 你有'dataType'設置爲'json' - 根據JSLint你的迴應是有效的 – tymeJV
你也想使用'success'選項而不是'complete '接收響應'數據'。這兩個事件沒有通過相同的參數。 –