Home > Blockchain >  Cannot deserialize the current JSON objectT into type because the type requires a JSON array (e.g. [
Cannot deserialize the current JSON objectT into type because the type requires a JSON array (e.g. [

Time:10-04

Im having issues trying to desearilize my json array its structure is like this

{
  "data": {
    "entityGraph": {
      "shipmentKey": 1,
      "shipmentId": "1",
      "autoRateOn": true,
      "billByCompanyKey": 1,
      "billingNotes": "",
      "billToCustomerKey": 1,
      "bookedBy": null,
      "bookedFor": 0,
      "bookedForUserKey": null,
      "cargoValue": 0,
      "contactKey": 1,
      "contactNote": "",
      "createdBy": 1,
      "createdOn": "2022-10-03T15:41:35.980Z",
      "customerKey": 1,
      "equipmentTypeKey": 1,
      "hasClaims": false,
      "invoiceNotes": "",
      "isHazmat": false,
      "isTeamRequired": false,
      "originalPaperworkReceivedOn": null,
      "paymentStatus": 0,
      "preloadedTrailerKey": null,
      "ratePlanKey": null,
      "reeferMode": 0,
      "reeferTemperature": 0,
      "referenceId1": "1",
      "referenceId2": "1",
      "referenceId3": "1",
      "referenceId4": "1",
      "referenceId5": "",
      "rowVersion": "AAAAAAAxX00=",
      "status": 1,
      "updatedBy": 1,
      "updatedOn": "2022-10-03T16:41:23.260Z",
      "locContact": {
        "contactKey": 1,
        "anniversaryDate": null,
        "contactGKey": null,
        "createdOn": "2022-10-03T15:41:35.980Z",
        "dateOfBirth": null,
        "emailAddress": "",
        "firstName": "",
        "lastName": "",
        "middleName": "",
        "phoneExt1": "",
        "phoneExt2": "",
        "phoneExt3": "",
        "phoneNumber1": "",
        "phoneNumber2": "",
        "phoneNumber3": "",
        "phoneType1": 0,
        "phoneType2": 0,
        "phoneType3": 0,
        "rowVersion": "AAAAAAAxXcs=",
        "title": "",
        "updatedOn": "2022-10-03T15:41:35.980Z",
        "webSite": "",
        "validationErrors": [

        ]
      },
      "dspShipmentItems": [
        {
          "shipmentItemKey": 1,
          "description": "",
          "fromShipmentStopKey": 1,
          "goodsKey": 1,
          "ordinal": 1,
          "palletsCount": 0,
          "rowVersion": "AAAAAAAxXc0=",
          "shipmentKey": 1,
          "toShipmentStopKey": 1,
          "unitsCount": 0,
          "volume": 0,
          "weight": 1,
          "validationErrors": [

          ]
        }
      ],
      "dspShipmentStops": [
        {
          "shipmentStopKey": 1,
          "addressKey": 1,
          "appointmentReference": "",
          "arrivedOnLocal": "2022-09-30T12:00:00.000Z",
          "arriveOnLocal": "2022-09-28T00:00:00.000Z",
          "contactKey": 1,
          "departedOnLocal": "2022-09-30T13:00:00.000Z",
          "directionsNotes": "",
          "dispatcherNotes": "",
          "driverNotes": "",
          "drivingDistance": 0,
          "geocodeInfoString": "",
          "hoursOfOperation": "",
          "isAppointmentRequired": false,
          "isAppointmentSet": false,
          "isDropAndHook": false,
          "lateWhenAfterLocal": "2022-09-28T23:59:00.000Z",
          "locationKey": 1,
          "referenceId1": "",
          "routeInfoString": "",
          "routeKey": null,
          "shipmentKey": 1,
          "stopNumber": 1,
          "tripKey": 1,
          "tripStopKey": 1,
          "type": 0,
          "locAddress": {
            "addressKey": 1,
            "address1": "",
            "address2": "",
            "addressGKey": null,
            "administrativeArea": "",
            "company": "",
            "countryKey": 1,
            "createdOn": "2022-10-03T15:41:35.980Z",
            "geocodingPrecision": 3,
            "latitude": 1,
            "longitude": -1,
            "municipality": "",
            "placedOn": "",
            "postalCode": "1",
            "rowVersion": "AAAAAAAxXcg=",
            "timeZoneKey": null,
            "updatedOn": "2022-10-03T15:41:35.980Z",
            "verificationStatus": 2,
            "validationErrors": [

            ]
          },
          "locContact": {
            "contactKey": 1,
            "anniversaryDate": null,
            "contactGKey": null,
            "createdOn": "2022-10-03T15:41:35.980Z",
            "dateOfBirth": null,
            "emailAddress": "",
            "firstName": "",
            "lastName": "",
            "middleName": "",
            "phoneExt1": "",
            "phoneExt2": "",
            "phoneExt3": "",
            "phoneNumber1": "0000000000",
            "phoneNumber2": "",
            "phoneNumber3": "",
            "phoneType1": 0,
            "phoneType2": 0,
            "phoneType3": 0,
            "rowVersion": "AAAAAAAxXco=",
            "title": "",
            "updatedOn": "2022-10-03T15:41:35.980Z",
            "webSite": "",
            "validationErrors": [

            ]
          },
          "validationErrors": [

          ]
        },
        {
          "shipmentStopKey": 1,
          "addressKey": 1,
          "appointmentReference": "",
          "arrivedOnLocal": "2022-10-03T09:00:00.000Z",
          "arriveOnLocal": "2022-10-03T00:00:00.000Z",
          "contactKey": 1,
          "departedOnLocal": "2022-10-03T10:00:00.000Z",
          "directionsNotes": "",
          "dispatcherNotes": "",
          "driverNotes": "",
          "drivingDistance": 1,
          "geocodeInfoString": "",
          "hoursOfOperation": "",
          "isAppointmentRequired": false,
          "isAppointmentSet": false,
          "isDropAndHook": false,
          "lateWhenAfterLocal": "2022-10-03T23:59:00.000Z",
          "locationKey": 1,
          "referenceId1": "",
          "routeInfoString": "",
          "routeKey": null,
          "shipmentKey": 1,
          "stopNumber": 2,
          "tripKey": 1,
          "tripStopKey": 1,
          "type": 1,
          "locAddress": {
            "addressKey": 1,
            "address1": "",
            "address2": "",
            "addressGKey": null,
            "administrativeArea": "",
            "company": "",
            "countryKey": 1,
            "createdOn": "2022-10-03T15:41:35.980Z",
            "geocodingPrecision": 3,
            "latitude": 1,
            "longitude": -1,
            "municipality": "",
            "placedOn": "",
            "postalCode": "1",
            "rowVersion": "AAAAAAAxXcc=",
            "timeZoneKey": null,
            "updatedOn": "2022-10-03T15:41:35.980Z",
            "verificationStatus": 2,
            "validationErrors": [

            ]
          },
          "locContact": {
            "contactKey": 1,
            "anniversaryDate": null,
            "contactGKey": null,
            "createdOn": "2022-10-03T15:41:35.980Z",
            "dateOfBirth": null,
            "emailAddress": "",
            "firstName": "",
            "lastName": "",
            "middleName": "",
            "phoneExt1": "",
            "phoneExt2": "",
            "phoneExt3": "",
            "phoneNumber1": "0000000000",
            "phoneNumber2": "",
            "phoneNumber3": "",
            "phoneType1": 0,
            "phoneType2": 0,
            "phoneType3": 0,
            "rowVersion": "AAAAAAAxXck=",
            "title": "",
            "updatedOn": "2022-10-03T15:41:35.980Z",
            "webSite": "",
            "validationErrors": [

            ]
          },
          "validationErrors": [

          ]
        }
      ],
      "rnpShipmentRevenues": [
        {
          "shipmentRevenueKey": 1,
          "adjustedRevenueAmount": 1,
          "description": "",
          "isCalculatedFromRatePlan": false,
          "isInvoiced": true,
          "isPosted": true,
          "isUsedForPercentageBasedPay": true,
          "ordinal": 1,
          "paymentTypeKey": 1,
          "quantity": 1,
          "rateAmount": 1,
          "revenueAmount": 1,
          "shipmentKey": 1,
          "validationErrors": [

          ]
        }
      ],
      "validationErrors": [

      ]
    },
    "notes": null,
    "documents": null,
    "lookupCache": null,
    "validationResult": false,
    "lock": null
  },
  "url": "",
  "serverTime": "2022-10-03T16:44:26.959Z",
  "timeTook": "00:00:00.2812942",
  "error": null
}

   

The way to desearilize was first organize my json in jsoneditoronline.org and create the class in json2charp the result of the class was like this

 public class Data
{
    [JsonProperty("entityGraph")]
    public List<EntityGraph> EntityGraph { get; set; }

    [JsonProperty("notes")]
    public object Notes { get; set; }

    [JsonProperty("documents")]
    public object Documents { get; set; }

    [JsonProperty("lookupCache")]
    public object LookupCache { get; set; }

    [JsonProperty("validationResult")]
    public bool ValidationResult { get; set; }

    [JsonProperty("lock")]
    public object Lock { get; set; }
}   

public class DspShipmentItem
{
    [JsonProperty("shipmentItemKey")]
    public int ShipmentItemKey { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("fromShipmentStopKey")]
    public int FromShipmentStopKey { get; set; }

    [JsonProperty("goodsKey")]
    public int GoodsKey { get; set; }

    [JsonProperty("ordinal")]
    public int Ordinal { get; set; }

    [JsonProperty("palletsCount")]
    public int PalletsCount { get; set; }

    [JsonProperty("rowVersion")]
    public string RowVersion { get; set; }

    [JsonProperty("shipmentKey")]
    public int ShipmentKey { get; set; }

    [JsonProperty("toShipmentStopKey")]
    public int ToShipmentStopKey { get; set; }

    [JsonProperty("unitsCount")]
    public int UnitsCount { get; set; }

    [JsonProperty("volume")]
    public int Volume { get; set; }

    [JsonProperty("weight")]
    public int Weight { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}


public class DspShipmentStop
{
    [JsonProperty("shipmentStopKey")]
    public int ShipmentStopKey { get; set; }

    [JsonProperty("addressKey")]
    public int AddressKey { get; set; }

    [JsonProperty("appointmentReference")]
    public string AppointmentReference { get; set; }

    [JsonProperty("arrivedOnLocal")]
    public object ArrivedOnLocal { get; set; }

    [JsonProperty("arriveOnLocal")]
    public DateTime ArriveOnLocal { get; set; }

    [JsonProperty("contactKey")]
    public int ContactKey { get; set; }

    [JsonProperty("departedOnLocal")]
    public object DepartedOnLocal { get; set; }

    [JsonProperty("directionsNotes")]
    public string DirectionsNotes { get; set; }

    [JsonProperty("dispatcherNotes")]
    public string DispatcherNotes { get; set; }

    [JsonProperty("driverNotes")]
    public string DriverNotes { get; set; }

    [JsonProperty("drivingDistance")]
    public double DrivingDistance { get; set; }

    [JsonProperty("geocodeInfoString")]
    public string GeocodeInfoString { get; set; }

    [JsonProperty("hoursOfOperation")]
    public string HoursOfOperation { get; set; }

    [JsonProperty("isAppointmentRequired")]
    public bool IsAppointmentRequired { get; set; }

    [JsonProperty("isAppointmentSet")]
    public bool IsAppointmentSet { get; set; }

    [JsonProperty("isDropAndHook")]
    public bool IsDropAndHook { get; set; }

    [JsonProperty("lateWhenAfterLocal")]
    public DateTime LateWhenAfterLocal { get; set; }

    [JsonProperty("locationKey")]
    public int LocationKey { get; set; }

    [JsonProperty("referenceId1")]
    public string ReferenceId1 { get; set; }

    [JsonProperty("routeInfoString")]
    public string RouteInfoString { get; set; }

    [JsonProperty("routeKey")]
    public object RouteKey { get; set; }

    [JsonProperty("shipmentKey")]
    public int ShipmentKey { get; set; }

    [JsonProperty("stopNumber")]
    public int StopNumber { get; set; }

    [JsonProperty("tripKey")]
    public object TripKey { get; set; }

    [JsonProperty("tripStopKey")]
    public object TripStopKey { get; set; }

    [JsonProperty("type")]
    public int Type { get; set; }

    [JsonProperty("locAddress")]
    public LocAddress LocAddress { get; set; }

    [JsonProperty("locContact")]
    public LocContact LocContact { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}

public class EntityGraph
{
    [JsonProperty("shipmentKey")]
    public int ShipmentKey { get; set; }

    [JsonProperty("shipmentId")]
    public string ShipmentId { get; set; }

    [JsonProperty("autoRateOn")]
    public bool AutoRateOn { get; set; }

    [JsonProperty("billByCompanyKey")]
    public int BillByCompanyKey { get; set; }

    [JsonProperty("billingNotes")]
    public string BillingNotes { get; set; }

    [JsonProperty("billToCustomerKey")]
    public int BillToCustomerKey { get; set; }

    [JsonProperty("bookedBy")]
    public object BookedBy { get; set; }

    [JsonProperty("bookedFor")]
    public int BookedFor { get; set; }

    [JsonProperty("bookedForUserKey")]
    public object BookedForUserKey { get; set; }

    [JsonProperty("cargoValue")]
    public int CargoValue { get; set; }

    [JsonProperty("contactKey")]
    public int ContactKey { get; set; }

    [JsonProperty("contactNote")]
    public string ContactNote { get; set; }

    [JsonProperty("createdBy")]
    public int CreatedBy { get; set; }

    [JsonProperty("createdOn")]
    public DateTime CreatedOn { get; set; }

    [JsonProperty("customerKey")]
    public int CustomerKey { get; set; }

    [JsonProperty("equipmentTypeKey")]
    public int EquipmentTypeKey { get; set; }

    [JsonProperty("hasClaims")]
    public bool HasClaims { get; set; }

    [JsonProperty("invoiceNotes")]
    public string InvoiceNotes { get; set; }

    [JsonProperty("isHazmat")]
    public bool IsHazmat { get; set; }

    [JsonProperty("isTeamRequired")]
    public bool IsTeamRequired { get; set; }

    [JsonProperty("originalPaperworkReceivedOn")]
    public object OriginalPaperworkReceivedOn { get; set; }

    [JsonProperty("paymentStatus")]
    public int PaymentStatus { get; set; }

    [JsonProperty("preloadedTrailerKey")]
    public object PreloadedTrailerKey { get; set; }

    [JsonProperty("ratePlanKey")]
    public object RatePlanKey { get; set; }

    [JsonProperty("reeferMode")]
    public int ReeferMode { get; set; }

    [JsonProperty("reeferTemperature")]
    public int ReeferTemperature { get; set; }

    [JsonProperty("referenceId1")]
    public string ReferenceId1 { get; set; }

    [JsonProperty("referenceId2")]
    public string ReferenceId2 { get; set; }

    [JsonProperty("referenceId3")]
    public string ReferenceId3 { get; set; }

    [JsonProperty("referenceId4")]
    public string ReferenceId4 { get; set; }

    [JsonProperty("referenceId5")]
    public string ReferenceId5 { get; set; }

    [JsonProperty("rowVersion")]
    public string RowVersion { get; set; }

    [JsonProperty("status")]
    public int Status { get; set; }

    [JsonProperty("updatedBy")]
    public int UpdatedBy { get; set; }

    [JsonProperty("updatedOn")]
    public DateTime UpdatedOn { get; set; }

    [JsonProperty("locContact")]
    public LocContact LocContact { get; set; }

    [JsonProperty("dspShipmentItems")]
    public List<RootDspShipmentItem> DspShipmentItems { get; set; }

    [JsonProperty("dspShipmentStops")]
    public List<RootDspShipmentStop> DspShipmentStops { get; set; }

    [JsonProperty("rnpShipmentRevenues")]
    public List<RootRnpShipmentRevenue> RnpShipmentRevenues { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}

public class LocAddress
{
    [JsonProperty("addressKey")]
    public int AddressKey { get; set; }

    [JsonProperty("address1")]
    public string Address1 { get; set; }

    [JsonProperty("address2")]
    public string Address2 { get; set; }

    [JsonProperty("addressGKey")]
    public object AddressGKey { get; set; }

    [JsonProperty("administrativeArea")]
    public string AdministrativeArea { get; set; }

    [JsonProperty("company")]
    public string Company { get; set; }

    [JsonProperty("countryKey")]
    public int CountryKey { get; set; }

    [JsonProperty("createdOn")]
    public DateTime CreatedOn { get; set; }

    [JsonProperty("geocodingPrecision")]
    public int GeocodingPrecision { get; set; }

    [JsonProperty("latitude")]
    public double Latitude { get; set; }

    [JsonProperty("longitude")]
    public double Longitude { get; set; }

    [JsonProperty("municipality")]
    public string Municipality { get; set; }

    [JsonProperty("placedOn")]
    public string PlacedOn { get; set; }

    [JsonProperty("postalCode")]
    public string PostalCode { get; set; }

    [JsonProperty("rowVersion")]
    public string RowVersion { get; set; }

    [JsonProperty("timeZoneKey")]
    public object TimeZoneKey { get; set; }

    [JsonProperty("updatedOn")]
    public DateTime UpdatedOn { get; set; }

    [JsonProperty("verificationStatus")]
    public int VerificationStatus { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}

public class LocContact
{
    [JsonProperty("contactKey")]
    public int ContactKey { get; set; }

    [JsonProperty("anniversaryDate")]
    public object AnniversaryDate { get; set; }

    [JsonProperty("contactGKey")]
    public object ContactGKey { get; set; }

    [JsonProperty("createdOn")]
    public DateTime CreatedOn { get; set; }

    [JsonProperty("dateOfBirth")]
    public object DateOfBirth { get; set; }

    [JsonProperty("emailAddress")]
    public string EmailAddress { get; set; }

    [JsonProperty("firstName")]
    public string FirstName { get; set; }

    [JsonProperty("lastName")]
    public string LastName { get; set; }

    [JsonProperty("middleName")]
    public string MiddleName { get; set; }

    [JsonProperty("phoneExt1")]
    public string PhoneExt1 { get; set; }

    [JsonProperty("phoneExt2")]
    public string PhoneExt2 { get; set; }

    [JsonProperty("phoneExt3")]
    public string PhoneExt3 { get; set; }

    [JsonProperty("phoneNumber1")]
    public string PhoneNumber1 { get; set; }

    [JsonProperty("phoneNumber2")]
    public string PhoneNumber2 { get; set; }

    [JsonProperty("phoneNumber3")]
    public string PhoneNumber3 { get; set; }

    [JsonProperty("phoneType1")]
    public int PhoneType1 { get; set; }

    [JsonProperty("phoneType2")]
    public int PhoneType2 { get; set; }

    [JsonProperty("phoneType3")]
    public int PhoneType3 { get; set; }

    [JsonProperty("rowVersion")]
    public string RowVersion { get; set; }

    [JsonProperty("title")]
    public string Title { get; set; }

    [JsonProperty("updatedOn")]
    public DateTime UpdatedOn { get; set; }

    [JsonProperty("webSite")]
    public string WebSite { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}


public class RnpShipmentRevenue
{
    [JsonProperty("shipmentRevenueKey")]
    public int ShipmentRevenueKey { get; set; }

    [JsonProperty("adjustedRevenueAmount")]
    public int AdjustedRevenueAmount { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("isCalculatedFromRatePlan")]
    public bool IsCalculatedFromRatePlan { get; set; }

    [JsonProperty("isInvoiced")]
    public bool IsInvoiced { get; set; }

    [JsonProperty("isPosted")]
    public bool IsPosted { get; set; }

    [JsonProperty("isUsedForPercentageBasedPay")]
    public bool IsUsedForPercentageBasedPay { get; set; }

    [JsonProperty("ordinal")]
    public int Ordinal { get; set; }

    [JsonProperty("paymentTypeKey")]
    public int PaymentTypeKey { get; set; }

    [JsonProperty("quantity")]
    public int Quantity { get; set; }

    [JsonProperty("rateAmount")]
    public int RateAmount { get; set; }

    [JsonProperty("revenueAmount")]
    public int RevenueAmount { get; set; }

    [JsonProperty("shipmentKey")]
    public int ShipmentKey { get; set; }

    [JsonProperty("validationErrors")]
    public List<object> ValidationErrors { get; set; }
}

public class Root
{
    [JsonProperty("data")]
    public List<Data> Data { get; set; }

    [JsonProperty("url")]
    public string Url { get; set; }

    [JsonProperty("serverTime")]
    public DateTime ServerTime { get; set; }

    [JsonProperty("timeTook")]
    public string TimeTook { get; set; }

    [JsonProperty("error")]
    public object Error { get; set; }
}

I think the error must be in the structure because inside the jsonproperty shipments are arrays inside and i think it must be another class Root but i'm not pretty sure

CodePudding user response:

fix the property Data, instead of list use just Data

public class Root
{
    [JsonProperty("data")]
    public Data Data { get; set; }
   .....
}

and fix the property EntityGraph, instead of list use just EntityGraph

public class Data
{
    [JsonProperty("entityGraph")]
    public EntityGraph EntityGraph { get; set; }
 .....
}

and fix these properties inside of EntityGraph class

    [JsonProperty("dspShipmentItems")]
    public List<DspShipmentItem> DspShipmentItems { get; set; }

    [JsonProperty("dspShipmentStops")]
    public List<DspShipmentStop> DspShipmentStops { get; set; }

    [JsonProperty("rnpShipmentRevenues")]
    public List<RnpShipmentRevenue> RnpShipmentRevenues { get; set; }

           // instead of 

//  [JsonProperty("dspShipmentItems")]
//  public List<RootDspShipmentItem> DspShipmentItems { get; set; }
//
//  [JsonProperty("dspShipmentStops")]
//  public List<RootDspShipmentStop> DspShipmentStops { get; set; }
//
//  [JsonProperty("rnpShipmentRevenues")]
//  public List<RootRnpShipmentRevenue> RnpShipmentRevenues { get; set; }
  • Related