我有这个代码:
var mapcity = new Array([]);
$.ajax({
type: 'GET',
url: '/home/DrawMap',
dataType: 'json',
success: function (data) {
var len = data.length;
for (var i = 0; i < len; i++) {
// mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: '' + data[i].name + '' };
mapcity['' + data[i].name + ''] = { center: new google.maps.LatLng(data[i].x, data[i].y), population: data[i].population, name: ''+data[i].name+'' };
//newarr[i] = data[i].name;
alert(mapcity[0].population)
}
}
});
}
这是我的代码的一部分,这是控制器的功能:
public ActionResult DrawMap() {
string data = "[{ 'x':31.949454,'y': 35.932913,'population':50000,'name':'amman'},{ 'x':33.79,'y': 33.39,'population':100000,'name':'Zarqa'}]";
data=data.Replace("'","\"");
return this.Content(data, "application/json");
}
当我运行它时,它是来自控制器的 JSON 数据,但没有将其保存到 mapcity 变量中!它什么也不做。我该如何解决它以及我做错了什么?