我是一位有用的助手,可以翻译文本。
我有一个简单的Web方法和Ajax调用,但仍然收到一个错误,说它无法将字符串转换为IDictionary对象??
这是Ajax调用:
这是一个webMethod:
这是我从FireBug看到的内容:
响应头 服务器:Microsoft-IIS/5.1 日期:Thu, 09 Apr 2009 21:43:59 GMT jsonerror:true 缓存控制:private 内容类型:application/json; charset=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 serializer, Boolean throwOnError, Object& convertedObject)\r\n 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\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"} 有人对此有任何想法吗?谢谢!
我有一个简单的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 日期:Thu, 09 Apr 2009 21:43:59 GMT jsonerror:true 缓存控制:private 内容类型:application/json; charset=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 serializer, Boolean throwOnError, Object& convertedObject)\r\n 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n 在 System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\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"} 有人对此有任何想法吗?谢谢!