0

我要开发一个交互式地图(谷歌地图)。坐标通过 ajax 从 json 解析,但我得到错误

JSON 格式

{"Level":[{"route":[{"lat":39.105251,"lgn":26.551727},
{"lat":39.105247125,"lgn":26.551774625}...],"balls":
[{"lat":39.105239375,"lgn":26.551869875},{"lat":39.10524325,"lgn":26.55182225}]},
{"route":[{........},{.....}...],"balls":[{........},{.....}...]}]}

AJAX 请求

$.ajax({
   type: "GET",
   url: "getcoordp?q=2",
   dataType: "json",
   cache: false,
   contentType: "application/json",
   success: function(data) {
  $.each(data.Level, function(i,Level){
    $.each(data.route, function(index, route) {
        alert(data.lat)
        });  
    }); 

   }
   });

错误

Uncaught TypeError: Cannot read property 'length' of undefined

有什么帮助吗?

4

2 回答 2

0

在下面替换

$.each(data.route, function(index, route)...

$.each(Level.route, function(index, route) {
    alert(route.lat)
});  

这将解决您的问题。

于 2013-08-18T05:14:45.157 回答
0

尝试这个

for(i=0;i<data.Level.length;i++){
console.log(data.Level[i].route);
}
于 2013-08-18T05:26:34.480 回答