【问题标题】:Json Deserialize abstract class $type in stringJson反序列化字符串中的抽象类$type
【发布时间】:2019-03-02 04:42:16
【问题描述】:

我正在尝试使用 newtonsoft deserializeobject 对下面的 json 进行反序列化,但出现以下错误。我怎样才能让它使用它在 json 中声明的类型和 $type 位?错误是真的,因为 VisitType 类是许多类的基本抽象类,FormType 就是其中之一。

无法创建 Messages.VisitType 类型的实例。类型是一个 接口或抽象类,不能实例化。小路 'tasks[0].Id',第 1 行,位置 103。

{
    "isFullyComplete":true,
    "tasks":[
              {
                 "$type":"Messages.FormType, Messages",
                 "Id":{"ref":"CP"},
                 "status":"Complete"
              }
            ],
     "identity":
              {
                "guid":"3fd3b1c2-c700-e911-8080-005056883684"
              },
              "proRef":"No"
 }

【问题讨论】:

    标签: c# .net json json.net


    【解决方案1】:

    就在我花了很长时间寻找的时候,我终于找到了答案:

    https://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm

    【讨论】:

      猜你喜欢
      • 2012-11-18
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多