【发布时间】:2010-10-18 16:11:44
【问题描述】:
我有一个简单的 web 方法和 ajax 调用,并继续收到一个错误,说它无法将字符串转换为 IDictionary 对象???
这里是ajax调用:
var params = '{"ID":"' + rowid + '"}';
$.ajax({
url: 'EDI.asmx/GetPartnerDetails',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(params),
dataType: "json", //not json . let me try to parse
success: function(msg, st) { . . . .
这里是webMethod:
<WebMethod()> _
Public Function GetPartnerDetails(ByVal ID As String) As String
'Dim objParam As IDictionary = CType(JsonConvert.DeserializeObject(ID), IDictionary)
'Dim rowID As String = objParam("ID")
Dim objController As New HealthComp.BLL.X12Partners.TradingPartnersController
Dim objInfo As TradingPartnersInfo = objController.FetchByPartnerID(Int32.Parse(ID))
Return JsonConvert.SerializeObject(objInfo)
End Function
这是我从 FireBug 看到的:
响应标头
服务器:Microsoft-IIS/5.1
日期:格林威治标准时间 2009 年 4 月 9 日星期四 21:43:59
json错误:真
缓存控制:私有
内容类型:应用程序/json;字符集=utf-8
内容长度:1331
POST: "{\"ID\":\"4\"}"
回复:
{"Message":"无法将 \u0027System.String\u0027 类型的对象转换为 \u0027System.Collections 类型 .Generic.IDictionary`2[System.String,System.Object]\u0027","StackTrace":" 在 System.Web.Script.Serialization .ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer 序列化器, Boolean 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain 处的 throwOnError, Object& convertObject)\r\n (Object o, Type type, JavaScriptSerializer 序列化器, Boolean throwOnError, Object&convertedObject )\r\n 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer 序列化程序)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer 序列化程序、字符串输入、类型类型、Int32 depthLimit)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer .Deserialize[T](字符串输入)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest (HttpContext 上下文,JavaScriptSerializer 序列化程序)\r\n 在 System.Web.Script.Services.RestHandler .GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n 在 System.Web.Script.Services .RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType" :"System.InvalidOperationException"}
有人对此有任何想法吗?谢谢!!
【问题讨论】:
标签: asp.net jquery web-services json parameters