我RestSharp在我的MVC项目中使用。我有这两个类可Models用于 API 数据。
public class ApiResponseON
{
public Data Data { get; set; }
}
public class Data
{
public string? comments { get; set; }
}
我正在使用 API 来返回这样的数据
public async Task<List<ApiResponseON>> GetJson(string on
{
RestRequest restRequest = new RestRequest($"/search?filter.on={on}&filter.status=All");
var data = await _restClient.GetAsync<List<ApiResponseON>>(restRequest);
return data;
}
但我的问题是我return data;在线上遇到了这个错误
System.InvalidCastException:'无法将'RestSharp.JsonArray'类型的对象转换为'System.Collections.Generic.IDictionary`2 [System.String,System.Object]'。
我需要在代码中进行哪些更改才能成功执行?
原始 Json
{
"TotalRecords":1,
"Skip":0,
"Take":100,
"ReturnCode":"Success",
"Data":[
{
"OrderUser":{
"Email":"",
"FullName":"",
"Username":"",
"FirstName":"",
"LastName":"",
"ExternalId":"",
"Custom01":"",
"Custom02":"",
"Custom03":"",
"UserGroupName":""
},
"OrderNumber":"",
"CurrencyCode":"USD",
"OrderTag":null,
"PoNumber":"",
"Comments":"4321",
"CompanyName":"",
"CompanyGuid":"00000000-0000-0000-0000-000000000000",
"CompanyId":2295,
"OrderStatus":"Active",
"AccountingUnit":null,
"EmailAddress":"",
"ShippinndHandling":0,
"Tax":0,
"Discount":0,
"OrderDate":"2017-10-28T12:16:30.453",
"ClosedDate":null,
"DesiredShipDate":"2017-11-03T23:59:59",
"Carrier":"Flat Rate",
"Shippinddress":{
"Company":"",
"Name":"",
"AddressLine1":"",
"AddressLine2":"",
"AddressLine3":"",
"City":"",
"State":"",
"Country":"US",
"ZipCode":"",
"PhoneNumber":"",
"ExternalId":null,
"Email":"",
"ShipmentCode":null
},
"Billinddress":{
"Company":"",
"Name":"",
"AddressLine1":"",
"AddressLine2":"",
"AddressLine3":null,
"City":"",
"State":"",
"Country":"US",
"ZipCode":"",
"PhoneNumber":"",
"ExternalId":null,
"Email":null,
"ShipmentCode":null
},
"Lines":[
{
"LineNumber":1,
"LineId":"",
"ApprovalReason":null,
"Price":0,
"DirectMailService":null,
"Status":"Released",
"EstimatedShipDate":"2017-11-03T23:59:59",
"Sku":"",
"PrintFileUrl":"",
"PrintFilename":"",
"ListFilUrl":null,
"ListFilename":"",
"Quantity":1,
"FileUrl":null,
"Thumbnail":null,
"UnitPrice":0,
"Part":{
"Id":1073225,
"Name":"",
"UnitCost":0,
"MinQuantity":0,
"MinQuantity2":0,
"MaxQuantity":99999,
"DaysOfStockMin":null,
"DateAvailable":"2017-10-18T00:00:00",
"Comments":"",
"CompanyExternalId1":"",
"CompanyExternalId2":"",
"HasListVariables":false,
"SiteId":127,
"CompanyId":2295,
"IsKit":false,
"IsLimitPartOrderQuantity":false,
"IsEdeliveryOnly":false,
"IsPersonalizeable":false,
"VendorName":null,
"VendorId":null,
"ShipmentGroupId":null,
"BoxSizeId":null,
"IsConfigurable":false,
"IsFixedAsset":false,
"Options":{
"PartOptionId":1222272,
"DateUpdated":"2017-10-18T10:30:43.503",
"IsCorporateListAllowed":false,
"IsEnforceMasterConfig":false,
"IsFulfillChargeExempt":false,
"IsMailingListRequired":false,
"IsPurchaseListAllowed":false,
"IsTaxExempt":false,
"IsUploadListAllowed":false,
"IsUploadListOnly":false,
"PartId":1073225,
"IsShippingExempt":false,
"ComponentItemType":null,
"ComponentMinCount":null,
"ComponentMaxCount":null,
"AllowNetiveDemand":null,
"TaxCode":null,
"UseListQtyForKitParts":false,
"IsShowBackorderAlert":null,
"ChiliDocumentId":null,
"IsFixedAsset":false,
"FixedAssetFrontBufferDays":null,
"FixedAssetBackBufferDays":null,
"IsBulkProofing":false,
"AllowCopyCustomization":null,
"IsForcedDynamicDatasource":false,
"AllowFacebook":false,
"AllowFacebookCaption":false,
"MailingListDeduplicationType":null
},
"UnitOfMeasure":null,
"ThumbnailFile":"image-not-found.png",
"Categories":[
],
"BoxSize":null,
"SourcingZip":null,
"SourcingId":null,
"IsShippingExempt":false,
"ProductionQueue":null,
"IsBulkProofing":false,
"IsOneToOneMailing":false,
"Rating":0,
"ReviewsCount":0
},
"VendorPart":null,
"Custom01":"",
"Custom02":"",
"Custom03":"",
"VendorId":null,
"Discount":0,
"DiscountName":null,
"DiscountKey":null,
"Weight":0,
"WeightedEstimatedShipping":0,
"EDeliveryUrl":"",
"FulfillCharge":0,
"IsEDelivery":false,
"IsTaxExempt":false,
"IsFullfillExempt":false,
"IsCustomized":false,
"DeliveryMethod":null,
"AccountingUnit":null,
"AccountingUnitDetails":null,
"ProofName":null,
"ProofInitial":null,
"ProofDate":null,
"ProducingPartner":null,
"Attributes":[
],
"PrintInfo":{
"NumberOfPages":0,
"FinishedTrimWidth":0,
"FinishedTrimHeight":0,
"Duplex":null,
"Bleed":null,
"Folds":null,
"PaperStock":null,
"PressSheetSize":null,
"NumberOut":null,
"BindarySpecifications":null,
"FlatSize":null,
"ProductionPress":null
},
"ShipmentLines":[
],
"RawMaterials":[
],
"CoopBucketName":null,
"ProofComments":"",
"IsFixedAsset":"N",
"RequestedArrivalDate":null,
"ExpectedReturnDate":null
}
],
"IsEDeliveryOnly":false,
"ShowInvoiceEmail":false,
"InvoiceEmail":"",
"InvoiceFee":0,
"Total":0,
"SubTotal":0,
"TotalMailingCost":0,
"IsExpedite":false,
"PartShippingCost":null,
"OrderFiles":[
],
"ThirdPartyAccountNumber":"",
"SignatureRequired":false
}
],
"Message":null,
"ErrorGuid":null
}