2013-02-22 17 views
0

我有此错误 无法将类型\ u0027System.String \ u0027的目的是输入\ u0027System.Collections.Generic.Dictionary 2[System.String,System.Int32]\u0027","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary 2 rawParams个)\ r \ n在System.Web程序。 Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target,IDictionary 2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary 2 rawParams)\ r \ n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context,WebServiceMethodData methodData)“,”ExceptionType“:”System.InvalidOperationException通对象的WebMethod与字典<string, int>放慢参数

当我传递数组到WebMethod与字典

+0

你想通过字典对象在webmehtod/webapi项目的参数? – Rusty 2013-02-22 11:38:46

+0

没有我让forloop在forloop中创建新的对象来推它在数组中,并使JSON.stringify(数组),但得到相同的错误 – eman 2013-02-22 12:00:47

回答

0

如果它是一个webap的web方法然后,我不能将列表或字典类型的对象传递给方法,只会传递字符串参数,传递此对象以将它们序列化为字符串,然后将其反序列化为列表或字典对象那个字符串。

WEBMETHOD消耗代码:

Dictionary<string,int> objstring = new Dictionary<string,int> 
var serializer = new JavaScriptSerializer(); 
var serializedstring = serializer.Serialize(objstring); 

,然后通过在参数的serializedstring。

做同样的反序列化只是从webapi方法中的序列化对象调用deserialize方法。

我希望这可以帮助你。

+0

我想通过JSON函数将Dictionary传递给WebMethod [WebMethod] public string save(Dictionary para ) { } – eman 2013-02-22 12:03:29

相关问题