0
我正在使用Newtonsoft.json。我無法理解反序列化的結果。 Bulletin.PageList正在填寫好的。但是,引用PageList的元素的頁面始終爲空。在JsonSerializerSettings中,我指定了PreserveReferencesHandling.All,但它沒有幫助。你能幫助解決頁面null的問題嗎?謝謝JSON。參考將反序列化爲空
JSON structure:
"Bulletins": [
{
"$id": "46b5efa80fe644d7bd525e2c30f5df8a",
"$type": "Bulletin",
"JSONNETTYPE": "Bulletin",
"PagesList": [
{
"id": "4ed13d727cd144d1acf1e0c9bc273245",
"JSONNETTYPE": "PageView",
"Number": 1,
"Id": "1a2b8ed4249948e194b396c46a5d1eeb",
"UiId": "4ed13d727cd144d1acf1e0c9bc273245"
}
],
"AgendaQuestions": [
{
"$id": "eceb6fe6c74a40d59f0673b76bd6dbb3",
"$type": "QSimple",
"Page": {
"$ref": "46b5efa80fe644d7bd525e2c30f5df8a#PagesList.0"
}
}
]
}]
C#結構:
public class Bulletin
{
public Bulletin()
{
}
public string Dbid { get; set; }
public List<PageView> PagesList;
public List<Question> AgendaQuestions;
}
public abstract class Question
{
protected Question(int number, string customNumberLabel = null)
{
Number = number;
CustomNumberLabel = customNumberLabel;
}
public int Number { get; set; }
public string CustomNumberLabel { get; set; }
public PageView Page { get; set; }
}
public class PageView
{
public int Number { get; set; }
public string Id { get; set; }
public int BulletinNumber { get; set; }
public PageView()
{
}
}
var settings = new JsonSerializerSettings
{ PreserveReferencesHandling = PreserveReferencesHandling.All
}