1

I am executing get API and want to retrieve a specific value from the JSON response. I want to get Job: URL value into a variable, but getting following error saying cannot deserialize Json object.

enter image description here

I am using following object model to map Json response.

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

Job and Items class objects:

 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; }
    
    
        }

Response return from the GET API execution gives the following IResponse as content. When I try to deserialize the response to retrieve URL value getting the above error. I am new to restsharp and appreciate if anyone could help me figure this out.

JSON response:

{
  "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
    }
  ]
}

This is how Postman response looks like:

enter image description here

Appreciate it if you can help me out to figure out.

Really appreciate your help.

Thank you.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
ChinS
  • 199
  • 2
  • 11
  • Please do not post images of code. Instead, copy and paste the code into your question text and click the code format button that looks like: `{ }` – Greg Burghardt Dec 02 '21 at 12:25
  • Sorry, @GregBurghardt for my bad. I have edited the post adding code to replace screenshots. – ChinS Dec 02 '21 at 22:27
  • Also try to add more context to explain my question here. I am pretty new to Restsharp and am currently try to work on the existing codebase while understanding it. Apologies for my inability to explain the issue clearly. Thank you. – ChinS Dec 02 '21 at 23:05
  • I formatted the JSON response. You can search "format json" in any search engine, and there are a bunch of free sites that allow you to quickly format JSON for readability. – Greg Burghardt Dec 03 '21 at 14:08

1 Answers1

0

I found the resolution for this issue. Job element is an object not a list. So changing the object model as below, the error was resolved.

public class Job
{
    public string Url { get; set; }
    public object Title { get; set; }
}
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
ChinS
  • 199
  • 2
  • 11