Which Json deserializer renders IList collections?

前端 未结 3 648
别跟我提以往
别跟我提以往 2021-02-06 18:51

I\'m trying to deserialize json to an object model where the collections are represented as IList types.

The actual deserializing is here:

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 19:19

    It is not possible to deserialize directly to an interface, as interfaces are simply a contract. The JavaScriptSerializer has to deserialize to some concrete type that implements IList, and the most logical choice is List. You will have to convert the List to a LazyList, which given the code you posted, should be easy enough:

    var list = serializer.Deserialize>(...);
    var lazyList = new LazyList(list);
    

提交回复
热议问题