1
我有一個weservice方法,無法將類型 'System.String' 的對象鍵入 'PropertySearch'
public string SearchProperties(string pPropertySearch, string pSort)
{
string[] _propSearch = pPropertySearch.Split(',');
string searchType = (_propSearch)[_propSearch.Length - 1];
List<Property> returnResults = new List<Property>();
try
{
PropertySearch _MyPropertySearch = (PropertySearch)JavaScriptConvert.DeserializeObject(pPropertySearch, typeof(PropertySearch));
returnResults = PropertyDALC.SearchPropertyNew(_MyPropertySearch, pSort, searchType, 25);
}
catch (Exception e)
{
}
string output = JavaScriptConvert.SerializeObject(returnResults);
return output;
}
PropertySearch.cs,
[Serializable]
public class PropertySearch
{
private string userId;
private string sessionId;
private string priceMin;
private string priceMax;
public string UserId
{
get { return userId; }
set { userId = value; }
}
public string SessionId
{
get { return sessionId; }
set { sessionId = value; }
}
public string PriceMin
{
get { return priceMin; }
set { priceMin = value; }
}
public string PriceMax
{
get { return priceMax; }
set { priceMax = value; }
}
public string BedsMin
{
get { return bedsMin; }
set { bedsMin = value; }
}
}
我已經給字符串「pPropertySearch 「爲:上調用按鈕點擊後
"0000-0000","gghuk","6666","8888"
,web服務調用和近此行
" PropertySearch _MyPropertySearch = (PropertySearch)JavaScriptConvert.DeserializeObject(pPropertySearch, typeof(PropertySearch));"
它給這個例外,
"Cannot convert object of type 'System.String' to type 'PropertySearch'"
有什麼不對的代碼。請糾正我。
我是否以錯誤的格式傳遞字符串?請幫忙。 我不知道這些序列化,webservice中的反序列化概念。
任何幫助表示讚賞!
@DSlangle,非常感謝! – Mahe