How to deserialize json objects into specific subclasses?

后端 未结 2 932
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 10:52

I have a Cabin class that contains a list of Row objects. I\'d like to serialize the objects like this, but when deserializing I\'d like the Row objects to be RowRule objec

2条回答
  •  一向
    一向 (楼主)
    2020-12-11 11:37

    The problem with your sample code is, you're creating object of Row and trying to get RowRule which is not possible.

    May be you wanted to do it like this:

            var cabin = new Cabin();
            var row = new RowRule(); // create derived object
            row.Status = "Success";
            cabin.Rows = new List()
            {
              row,
              row
            };
    

提交回复
热议问题