我從python服務器接收json文件,我嘗試使用ajax進行解析,以便在單獨的下拉菜單中根據類別(egdata_provider,人口普查)顯示值。但是我經常得到以下內容錯誤: 未捕獲錯誤:語法錯誤,無法識別的表達式:[{「data_provider」:「census」,「data_year」:「2010」,「data_series」:「sf1」,「tb_name」:「h1」,「summ_level」: 「160」},{「data_provider」:「census」,「data_year」:「2010」,「data_series」:「sf1」,「tb_name」:「p1」,「summ_level」:「050」}]使用ajax解析json
請幫助我!以下是我寫的代碼。
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
function codeAddress() {
var ajax = $.ajax({
//data : params,
type : "GET",
crossDomain: true,
dataType: "json",
//jsonp: "callback",
//callbackParameter: "callback",
//contentType : "application/x-www-form-urlencoded",
url : "http://0.0.0.0:8080/"
});
ajax.done(function() {
var response=ajax.responseText;
var json = jQuery.parseJSON(response);
$(json).each(function(i,val){
$.each(val,function(k,v){
console.log(k+" : "+ v);
});
});
});
ajax.fail(function() {
alert("fail");
});
ajax.always(function() {
alert("done");
});
}
</script>
</head>
<body id="b1" onload="codeAddress();">
</body>
</html>
鑑於你的JSON和代碼(但網址更改爲一個在那裏我已經主持了JSON) ,[我不能重現該問題](http://jsbin.com/kefitesu/1/)。 – Quentin
@Quentin字符串中是否可能有未轉義的UTF控制字符? – crush
@crush - 或任何隱形角色。這是相當可能的問題。 – Quentin