我使用Wcf服务和JS.
我通过AJAX向我的服务发送信息.
我在服务中有一个接受以下对象的函数:
[DataContract]
public class Business
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Desc { get; set; }
[DataMember]
public List
BusinessService.cs:
[DataContract]
public class BusinessService
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Desc { get; set; }
[DataMember]
public int LongTime { get; set; }
}
我将JS中的对象解析为JSON并将它们发送到服务.
这里发送到wcf函数的json:
"{"ManageBusiness":{"Name":"aaaaaa","Desc":"aaaaaaaaaaaa","Services":[{"Name":"aaaaaa","Desc":"aaaaaa","LongTime":30},{"Name":"aaaaaa1","LongTime":30}]}}"
除服务列表外,一切正常.
该列表以wcf函数为空.
我不知道为什么会这样,我会很感激帮助吗?
最佳答案
您无法实例化List< T>来自JSON数据.您可以做的是替换:
原文链接:https://www.f2er.com/jquery/428241.html[DataContract]
public class Business
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Desc { get; set; }
[DataMember]
public List
同
[DataContract]
public class Business
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Desc { get; set; }
[DataMember]
public BusinessService[] Services { get; set; }
}
也就是说,替换List< T>与数组的T