我通过下面的脚本获取xml文件但是如何在C#页面上保存和访问? “http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US”
function markicons() {
InitializeMap();
var ltlng = [];
ltlng.push(new google.maps.LatLng(17.22, 78.28));
ltlng.push(new google.maps.LatLng(13.5, 79.2));
ltlng.push(new google.maps.LatLng(15.24, 77.16));
map.setCenter(ltlng[0]);
for (var i = 0; i <= ltlng.length; i++) {
marker = new google.maps.Marker({
map: map,
position: ltlng[i]
});
(function (i, marker) {
google.maps.event.addListener(marker, 'click', function () {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent("Message" + i);
infowindow.open(map, marker);
});
})(i, marker);
}
}
window.onload = markicons;
“
答案 0 :(得分:0)
看起来您需要在客户端javascript中访问该文件。你需要使用ajax: 以下是jQuery的示例:
$.ajax({
url: 'http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US',
success: function(resultDocuement){ alert(resultDocuement); },
dataType: 'json'
});
'resultDocuement'将包含json
中URL的结果答案 1 :(得分:0)
首先你没有得到一个xml,你有一个json文件,无论如何你可以用这个来保存你的json文件:
var client = new WebClient();
client.Headers.Add("User-Agent", "Nobody");
var response = client.DownloadString(new Uri("http://maps.googleapis.com/maps/api/directions/json?origin=41.90119000000001,-87.62979000000001&destination=34.052360,-118.243560&sensor=false&units=metric&language=en-US"));
File.WriteAllText(@"c:\logs\yourjson.json", response.ToString());