This is my JSON string:
{"id":320,"product":{"id":132,"identifier":"M365-ExchangeOnline-Plan2","_info":{"catalog_href":"https://sandbox-na.myconnectwise.net/v4_6_release/apis/3.0//procurement/catalog/132"}},"quantity":1.00,"lessIncluded":0.00,"unitPrice":8.000000,"unitCost":6.400000,"billCustomer":"Billable","effectiveDate":"2022-03-01T00:00:00Z","taxableFlag":true,"serialNumber":"Unite Office365","invoiceDescription":"Microsoft Office 365: Exchange Online (Plan 2)\n Jennifer Shields","purchaseItemFlag":false,"specialOrderFlag":false,"agreementId":180,"description":"Microsoft Office 365: Exchange Online (Plan 2)","billedQuantity":1.00,"uom":"Each","extPrice":8.000000,"extCost":6.400000,"sequenceNumber":3.00,"margin":1.600000,"prorateCost":0.000000,"proratePrice":0.000000,"extendedProrateCost":0.000000,"extendedProratePrice":0.000000,"prorateCurrentPeriodFlag":false,"agreementStatus":"Active","invoiceGrouping":{"id":9,"name":"Microsoft-365","description":"Microsoft 365","showPriceFlag":true,"showSubItemsFlag":true,"groupParentChildAdditionsFlag":false,"_info":{"invoiceGrouping_href":"https://sandbox-na.myconnectwise.net/v4_6_release/apis/3.0//procurement/invoicegrouping/9"}},"_info":{"lastUpdated":"2022-12-04T20:41:27Z","updatedBy":"Unite"},"customFields":[{"id":12,"caption":"Internal Notes","type":"TextArea","entryMethod":"EntryField","numberOfDecimals":0},{"id":19,"caption":"Additional Customer Notes","type":"TextArea","entryMethod":"EntryField","numberOfDecimals":0}]}
I got error on this line:
Dim roots As List(Of Root) = Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of Root))(json)
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[CWDash.CWDash.pagAPIReport+Root]' because the type requires a JSON array (e.g. [1,2,3]) to desterilize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be desterilized from a JSON object.
JsonObjectAttribute can also be added to the type to force it to desterilize from a JSON object. Path 'id', line 1, position 6.'
Public Class Root
Public Property id As Integer
Public Property name As String
Public Property type As Type
Public Property company As Company
Public Property contact As Contact
Public Property parentAgreement As ParentAgreement
Public Property site As Site
Public Property location As Location
Public Property department As Department
Public Property restrictLocationFlag As Boolean
Public Property restrictDepartmentFlag As Boolean
Public Property startDate As DateTime
Public Property noEndingDateFlag As Boolean
Public Property cancelledFlag As Boolean
Public Property sla As Sla
Public Property applicationUnits As String
Public Property applicationLimit As Double
Public Property applicationCycle As String
Public Property applicationUnlimitedFlag As Boolean
Public Property oneTimeFlag As Boolean
Public Property coverAgreementTime As Boolean
Public Property coverAgreementProduct As Boolean
Public Property coverAgreementExpense As Boolean
Public Property coverSalesTax As Boolean
Public Property carryOverUnused As Boolean
Public Property allowOverruns As Boolean
Public Property expireWhenZero As Boolean
Public Property chargeToFirm As Boolean
Public Property employeeCompRate As String
Public Property employeeCompNotExceed As String
Public Property compHourlyRate As Double
Public Property compLimitAmount As Double
Public Property billingCycle As BillingCycle
Public Property billOneTimeFlag As Boolean
Public Property billingTerms As BillingTerms
Public Property invoicingCycle As String
Public Property billToCompany As BillToCompany
Public Property billToContact As BillToContact
Public Property billToSite As BillToSite
Public Property billAmount As Double
Public Property taxable As Boolean
Public Property billStartDate As DateTime
Public Property taxCode As TaxCode
Public Property restrictDownPayment As Boolean
Public Property prorateFlag As Boolean
Public Property invoiceDescription As String
Public Property topComment As Boolean
Public Property bottomComment As Boolean
Public Property billTime As String
Public Property billExpenses As String
Public Property billProducts As String
Public Property billableTimeInvoice As Boolean
Public Property billableExpenseInvoice As Boolean
Public Property billableProductInvoice As Boolean
Public Property currency As Currency
Public Property autoInvoiceFlag As Boolean
Public Property nextInvoiceDate As DateTime
Public Property companyLocation As CompanyLocation
Public Property agreementStatus As String
Public Property _info As Info
Public Property customFields As List(Of CustomField)
Public Property customerPO As String
Public Property opportunity As Opportunity
Public Property invoiceTemplate As InvoiceTemplate
Public Property product As Product
Public Property agreementId As Integer
Public Property invoiceGrouping As invoiceGrouping
Public Property quantity As Integer
Public Property unitPrice As Double
Public Property billCustomer As String
Public Property effectiveDate As DateTime
Public Property billedQuantity As Integer
Public Property extPrice As Double
Public Property sequenceNumber As Integer
Public Property margin As Double
End Class
what wrong?