2013-02-22 28 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

相關問題