我的课堂结构如下
namespace Eauction
{
[DataContract(Namespace = "")]
public class SaleListJS
{
public SaleListJS()
{
this.SaleDataJS = new HashSet<SaleDataJS>();
}
[DataMember]
public string AuctionId { get; set; }
[DataMember]
public int DepotId { get; set; }
[DataMember]
public string Depot_Name { get; set; }
[DataMember]
public string Sale_Date { get; set; }
public virtual ICollection<SaleDataJS> SaleDataJS { get; set; }
}
[DataContract(Namespace = "")]
public class SaleDataJS
{
[DataMember]
public string SNo { get; set; }
[DataMember]
public string Speices_Name { get; set; }
[DataMember]
public string LotNo_Year { get; set; }
[DataMember]
public string Stack_No { get; set; }
[DataMember]
public string Grade { get; set; }
[DataMember]
public string Length { get; set; }
[DataMember]
public string Mid_Girth { get; set; }
[DataMember]
public string No_Of_Piece { get; set; }
[DataMember]
public string Volume { get; set; }
[DataMember]
public string Floor_Price { get; set; }
[DataMember]
public string AuctionId { get; set; }
public virtual SaleListJS SaleListJS { get; set; }
}
}
和像这样的服务
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "uploadSalelist")]
string UploadSalelist(SaleListJS sl);
}
public class Service1 : IService1
{
public string UploadSalelist(SaleListJS sl)
{
string returnBool = "false";
if (sl != null)
{
try
{
string depotId = sl.DepotId.ToString();
string depotName = sl.Depot_Name;
string auctionDate = sl.Sale_Date.ToString();
if (sl.SaleDataJS != null)
{
foreach (SaleDataJS sld in sl.SaleDataJS)
{
}
}
returnBool = "true";
}
catch (Exception ex)
{
returnBool = ex.Message;
}
}
return returnBool;
}
}
当我用邮递员调用它时,它总是返回&#39; SaleDataJS&#39; null但是&#39; SaleListJS&#39;不为空
我的Json是
{
"sl":{
"DepotId":"12",
"Depot_Name":"Lucknow",
"Sale_Date":"11\/30\/2016",
"SaleDataJS":[
{
"SNo":"1",
"Speices_Name":"Neem",
"LotNo_Year":"370/NC/14-15",
"Stack_No":"48/14-15",
"Grade":"II",
"Length":"0.95",
"Mid_Girth":"121 - 150",
"No_Of_Piece":"15",
"Volume":"0.0928",
"Floor_Price":"6715"
},
{
"SNo":"1",
"Speices_Name":"Neem",
"LotNo_Year":"370/NC/14-15",
"Stack_No":"48/14-15",
"Grade":"II",
"Length":"1.95",
"Mid_Girth":"121 - 150",
"No_Of_Piece":"5",
"Volume":"0.2202",
"Floor_Price":"6715"
}
]
}
}
请帮助我,我现在处于危机中。
答案 0 :(得分:0)
从
改变public virtual ICollection<SaleDataJS> SaleDataJS { get; set; }
到
[DataMember]
public virtual ICollection<SaleDataJS> SaleDataJS { get; set; }
为我工作。