【发布时间】:2013-06-12 06:17:15
【问题描述】:
我有一个 weservice 方法,
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"
当点击 InVoke 按钮时,webservice 被调用并在这一行附近
" PropertySearch _MyPropertySearch = (PropertySearch)JavaScriptConvert.DeserializeObject(pPropertySearch, typeof(PropertySearch));"
它给出了这个例外,
"Cannot convert object of type 'System.String' to type 'PropertySearch'"
这段代码有什么问题。请纠正我。
我是否以错误的格式传递字符串?请帮忙。 webservice中的这些序列化、反序列化概念我不知道。
感谢任何帮助!
【问题讨论】:
标签: .net json web-services deserialization