【发布时间】:2011-12-08 11:37:19
【问题描述】:
我在 aspx 页面的 javascript 函数中得到一个 JSON 对象。我需要从我的代码隐藏文件中获取这些数据。我该怎么做?
我的javascript函数是:
function codeAddress()
{
var address = document.getElementById("address").value;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location });
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
var requestParameter = '{' +
'output:"' + results + '"}';
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
data: requestParameter,
//contentType: "plain/text",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function() { alert("error"); }
});
});
}
Default.aspx.cs
[WebMethod]
public static string GetData( Object output)
{
return output.ToString();
}
我将输出作为对象数组而不是实际结果 - [object Object],[object Object],[object Object]。请为我提供获得实际结果的解决方案。我正在处理的 JSON 如下所示 http://maps.googleapis.com/maps/api/geocode/json?address=M%20G%20Road&sensor=false
【问题讨论】:
标签: c# javascript jquery .net json