- JScript code
var jsonData; $.ajax({ type: "Get", url: "/jsn.html", dataType: "text", global: false, async: false, success: function (strReult) { jsonData=eval("("+strReult+")"); }, error: function () { alert("Ajax请求数据失败!"); } }); for(var i=0;i<jsonData.city.data.length;i++){ alert(jsonData.city.data.name); }
这是jsn.html里面的数据:
- JScript code
{"city":{ "data":[ {"a":116.420605,"b":40.080577,"name":"碧水宾馆",address:"天通北苑一区甲6"}, {"a":116.42048,"b":40.056286,"name":"悦嘉酒店",address:"北京市朝阳区汤立路218号明天生活馆B座"}, {"a":116.668862,"b":40.120904,"name":"北京顺则兴商店",address:"北京市顺义区xx"} ] } }
------解决方案--------------------
- JScript code
//alert(jsonData.city.data.name);//少了索引了 alert(jsonData.city.data[i].name);