JSON 尝试重新序列化 restsharp 响应时出现反序列化错误

JSON deserialization error when try to reserialize restsharp response

我正在执行 get API 并想从 JSON 响应中检索特定值。我想获取 Job: URL value 到一个变量中,但是出现以下错误提示 cannot deserialize Json object.

我正在使用以下对象模型来映射 Json 响应。

class BlujayGetJobResponse
{
    public int TotalCount { get; set; }
    public string PreviousPage { get; set; }
    public string NextPage { get; set; }
    public List<Items> Items { get; set; }
}

工作和项目 class 个对象:

 public class Job
        {
            public string Url { get; set; }
            public string Title { get; set; }
        }
        public class Items
        {
            //public List<Consignment> Consignment { get; set; }
            public string Id { get; set; }
            public string DateCreated { get; set; }
            public string Gps { get; set; }
            public string ProcessOutcome { get; set; }
            public string ProcessOutcomeInternal { get; set; }
            public string ProcessType { get; set; }
            public string ProcessTypeInternal { get; set; }
            public string CallingCard { get; set; }
            public string AdhocLocation { get; set; }
            public string ProcessOutcomeReason { get; set; }
            public string ProcessOutcomeReasonInternal { get; set; }
            public string ProcessOutcomeReasonText { get; set; }
            public string IntendedTime { get; set; }
            public string SafePlace { get; set; }
            public string DeliveredToNeighbour { get; set; }
            public string NeighbourAddress { get; set; }
            public string IdentificationDetails { get; set; }
            public List<Job> Job { get; set; }
    
    
        }

来自 GET API 执行的响应 return 给出以下 IResponse 作为内容。当我尝试反序列化响应以检索 URL 值时出现上述错误。我是 restsharp 的新手,如果有人能帮我解决这个问题,我将不胜感激。

JSON 回复:

{
  "TotalCount":2,
  "PreviousPage":null,
  "NextPage":null,
  "Items":[
    {
      "Id":"5f67fc87-4dab-4c98-bde9-8ca3ba327052",
      "DateCreated":"\/Date(1638372363000+1300)\/",
      "Gps":null,
      "ProcessOutcome":"SUC",
      "ProcessOutcomeInternal":"31",
      "ProcessType":"OFD",
      "ProcessTypeInternal":"3",
      "CallingCard":null,
      "AdhocLocation":null,
      "ProcessOutcomeReason":null,
      "ProcessOutcomeReasonInternal":null,
      "ProcessOutcomeReasonText":null,
      "IntendedTime":null,
      "SafePlace":null,
      "DeliveredToNeighbour":false,
      "NeighbourAddress":null,
      "IdentificationDetails":null,
      "Job":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Jobs/a08064c8-85fb-4e5e-8ef3-2bd24409b8d0",
        "Title":null
      },
      "Location":null,
      "Packages":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/5f67fc87-4dab-4c98-bde9-8ca3ba327052/Packages/",
        "Title":null
      },
      "Signatures":null,
      "User":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Users/126",
        "Title":null
      },
      "Link":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/5f67fc87-4dab-4c98-bde9-8ca3ba327052",
        "Title":null
      },
      "TransactionId":null
    },
    {
      "Id":"33b0c532-3ca5-4eee-a1db-d012cae064ea",
      "DateCreated":"\/Date(1638419167000+1300)\/",
      "Gps":null,
      "ProcessOutcome":"DELCRE",
      "ProcessOutcomeInternal":"330",
      "ProcessType":"DEL",
      "ProcessTypeInternal":"1",
      "CallingCard":null,
      "AdhocLocation":null,
      "ProcessOutcomeReason":null,
      "ProcessOutcomeReasonInternal":null,
      "ProcessOutcomeReasonText":null,
      "IntendedTime":null,
      "SafePlace":null,
      "DeliveredToNeighbour":false,
      "NeighbourAddress":null,
      "IdentificationDetails":null,
      "Job":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Jobs/d9b93ae1-2b37-400b-ad43-978bbad024d9",
        "Title":null
      },
      "Location":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Depots/53",
        "Title":null
      },
      "Packages":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/33b0c532-3ca5-4eee-a1db-d012cae064ea/Packages/",
        "Title":null
      },
      "Signatures":null,
      "User":null,
      "Link":{
        "Url":"https://freightways-uat.mobilestar.blujaysolutions.net:444/API/v2/Actions/33b0c532-3ca5-4eee-a1db-d012cae064ea",
        "Title":null
      },
      "TransactionId":null
    }
  ]
}

这是 Postman 响应的样子:

如能帮我解答,不胜感激

非常感谢您的帮助。

谢谢。

我找到了这个问题的解决方案。 Job 元素是一个对象而不是列表。所以如下更改对象模型,错误已解决。

public class Job
{
    public string Url { get; set; }
    public object Title { get; set; }
}