0
我試圖使用Newtonsoft.Json.JsonConvert反序列化一個Json到我的對象中。 我的JSON是:{"SelectedContentsID[]":"31807,32493,39517","pageSize":"20","SisconContentSubDialogEnum":"0","searchCriteria":"","pageIndex":"1"}
反序列化包含int列表的屬性作爲屬性
和相應的類是:
[DataContract]
public class ContentGetHandlerDTO : ListBaseHandlerDto
{
[DataMember(Name = "SelectedCourseId")]
public int SelectedCourseId { get; set; }
[DataMember]
public System.Collections.Generic.List<int> SelectedContentsID { get; set; }
public ContentGetHandlerDTO() {
this.SelectedContentsID = new System.Collections.Generic.List<int>();
}
}
的ListBaseHandlerDto僅僅是包含一些公共屬性的類。 問題是,反序列化器方法只是忽略int列表並帶出一個空列表。
謝謝扎克,它發生的原因是從字典到JSON的序列化,使用JavaScriptSerializer。 現在,我正面臨着其他問題:反序列化器正在拋出:「無法投射或從System.String轉換爲System.Collections.Generic.List'1 [System.Int32]。」 – user3139501
如果這是正確的答案,請點擊勾號標記。 –
我很樂意提供幫助,但您需要將此標記爲正確答案,並開始一個新問題,因爲問題現在有所不同。 :) –