我想通過AJAX調用在我的地圖上獲取一些數據。但我收到以下錯誤:SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
。我做了console.log(dataArray)
。問題是我之前在我的應用程序中實現的兩個數據集確實工作並出現在屏幕上,但是當我試圖實現第三個數據集時,出現此錯誤,並且變量dataArray
保持空白。如何解決以下錯誤:JSON.parse:JSON數據第1行第1列的數據意外結束?
geojson_popupInfo = {
"type": "FeatureCollection",
"features": [],
};
geojson_dataTable = {
"type": "FeatureCollection",
"features": [],
};
var dataArray = data.split(", ;");
dataArray.pop();
dataArray.forEach(function(d){
d = d.split(", ");
var feature_popupInfo = {
"type": "Feature",
"properties": {},
"geometry": JSON.parse(d[fieldList.length])
};
var feature_dataTable = {
"type": "Feature",
"properties": {},
"geometry": JSON.parse(d[fieldList.length])
};
for (var i=0; i<fieldList.length; i++){
if ([fieldList[i].show_field] == 't') {
feature_popupInfo.properties[fieldList[i].field_alias] = d[i];
}
feature_dataTable.properties[fieldList[i].field_name] = d[i];
};
geojson_popupInfo.features.push(feature_popupInfo);
geojson_dataTable.features.push(feature_dataTable);
});
console.log(dataArray)
請確保數組的每個元素都是有效的JSON:'console.log(JSON.parse(d [fieldList.length]))' –
您能向我們展示您的AJAX調用。在不知道數據和fieldList是什麼樣的情況下,我們無法幫到你。 –
更新了代碼@Tomasz Nguyen。但奇怪的是,其他兩個數據集的工作,最後一個不是。 (不工作的數據集相當大,但對POST方法應該沒有問題) –