C# 无法反序列化当前JSON对象

C# 无法反序列化当前JSON对象,c#,asp.net-mvc,C#,Asp.net Mvc,无法将当前的JSON对象(例如{“名称”:“值”})反序列化为类型'System.Collections.Generic.List1[NIPRA.Models.OrderHeaderResult],因为该类型需要一个JSON数组(例如[1,2,3])才能正确反序列化 若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或者更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是像integer这样的基元类型,不是像数组或列表这样的集合类型)。还可以将J

无法将当前的
JSON
对象(例如
{“名称”:“值”}
)反序列化为类型
'System.Collections.Generic.List
1[NIPRA.Models.OrderHeaderResult],因为该类型需要一个
JSON数组(例如[1,2,3])才能正确反序列化

若要修复此错误,请将
JSON
更改为
JSON数组(例如[1,2,3])
,或者更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是像
integer
这样的基元类型,不是像数组或列表这样的集合类型)。还可以将JsonObjectAttribute添加到类型中,以强制它从JSON对象反序列化

路径“订单”,第1行,位置10。 Json数据:

{"Orders":
[{"Id":397908,
"BuyerId":1831,
"DateCreated":"2016-02-16T10:58:55",
"DateUpdated":"2016-02-16T10:58:55",
"DeliveryDate":"2015-01-20T00:00:00",
"UploadDate":"2016-02-16T10:58:55",
"InvoiceToName":"Lancet Laboratories (Pty) Ltd",
"OrderDate":"2016-02-16T08:58:55",
"OrderNumber":"PTYPO000006",
"OrderStatusId":1,
"OrderTotal":42050.3500,
"OrderTypeId":2,
"PartnerId":"V0002066  ",
"SupplierAccountName":"Bio-Rad Laboratories (Pty) Ltd",
"SupplierId":1696,
"ShipToName":"Rich Corn",
"SystemOrderStatusId":1,
"TermsOfPayment":"30DS",
"Supplier":null,
"Buyer":"Lancet Laboratories",
"BuyerName":"juri.vdv",
"BuyerAccountNumber":"",
"OrderStatus":"Requested",
"OrderType":"PURCHASE",
"HasComments":"No",
"TotalExcludingVAT":36886.2700,
"VATAmount":5164.0800,"AmendedBy":"System",
"FileName":""}],
"TotalPages":2}

我的viewmodel:

public partial class OrderHeaderView
{
    [JsonProperty("id")]
    public int Id { get; set; }
    [JsonProperty("buyerId")]
    public int BuyerId { get; set; }
    [JsonProperty("dateCreated")]
    public System.DateTime DateCreated { get; set; }
    [JsonProperty("dateUpdated")]
    public System.DateTime DateUpdated { get; set; }
    [JsonProperty("deliveryDate")]
    public Nullable<System.DateTime> DeliveryDate { get; set; }
    [JsonProperty("uploadDate")]
    public Nullable<System.DateTime> UploadDate { get; set; }
    [JsonProperty("invoiceToName")]
    public string InvoiceToName { get; set; }
    [JsonProperty("orderDate")]
    public Nullable<System.DateTime> OrderDate { get; set; }
    [JsonProperty("orderNumber")]
    public string OrderNumber { get; set; }
    [JsonProperty("orderStatusId")]
    public int OrderStatusId { get; set; }
    [JsonProperty("orderTotal")]
    public decimal OrderTotal { get; set; }
    [JsonProperty("orderTypeId")]
    public int OrderTypeId { get; set; }
    [JsonProperty("partnerId")]
    public string PartnerId { get; set; }
    [JsonProperty("supplierAccountName")]
    public string SupplierAccountName { get; set; }
    [JsonProperty("supplierId")]
    public int SupplierId { get; set; }
    [JsonProperty("shipToName")]
    public string ShipToName { get; set; }
    [JsonProperty("systemOrderStatusId")]
    public Nullable<int> SystemOrderStatusId { get; set; }
    [JsonProperty("termsOfPayment")]
    public string TermsOfPayment { get; set; }
    [JsonProperty("supplier")]
    public string Supplier { get; set; }
    [JsonProperty("buyer")]
    public string Buyer { get; set; }
    [JsonProperty("buyerName")]
    public string BuyerName { get; set; }
    [JsonProperty("buyerAccountNumber")]
    public string BuyerAccountNumber { get; set; }
    [JsonProperty("orderStatu")]
    public string OrderStatus { get; set; }
    [JsonProperty("orderType")]
    public string OrderType { get; set; }
    [JsonProperty("hasComments")]
    public string HasComments { get; set; }
    [JsonProperty("totalExcludingVAT")]
    public decimal TotalExcludingVAT { get; set; }
    [JsonProperty("vatAmount")]
    public decimal VATAmount { get; set; }
    [JsonProperty("amendedBy")]
    public string AmendedBy { get; set; }
    [JsonProperty("fileName")]
    public string FileName { get; set; }
    [JsonProperty("hasDelivery")]
    public bool HasDelivery { get; set; }
}

public async Task GetOrders(int statusId,int page,string关键字,int year)
{
_client.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“bearer”,UserToken.AccessToken);
var result=await_client.GetAsync($“api/invoicing/getorders?statusId={statusId}&page={page}&keyword={keyword}&year={year}”);
if(结果。IsSuccessStatusCode)
{
var orderData=await result.Content.ReadAsStringAsync();
返回JsonConvert.DeserializeObject(orderData);
}
其他的
返回null;
}

控制器:

    [HttpGet]
    public async Task<ActionResult> Index(int? id, int?page, string keyword, int?year)
    {
        _orderService.UserToken = base.Token;

        var orders = await  _orderService.GetOrders(id??1,page??2,keyword,year??DateTime.Now.Year);
         return View(orders);

    }
[HttpGet]
公共异步任务索引(int?id,int?page,字符串关键字,int?year)
{
_orderService.UserToken=base.Token;
var orders=await_orderService.GetOrders(id??1,第2页,关键字,年份??日期时间.Now.year);
返回视图(订单);
}

请提供帮助,以及如何在razor视图上显示此内容?

您的JSON看起来绝对不像一个集合。
您只有一个JSON对象,这在
OrderHeaderResult
类中有正确的描述

试着改变

JsonConvert.DeserializeObject<List<OrderHeaderResult>>(orderData);
JsonConvert.DeserializeObject(orderData);

JsonConvert.DeserializeObject(orderData);

您的JSON看起来绝对不像一个集合。
您只有一个JSON对象,这在
OrderHeaderResult
类中有正确的描述

试着改变

JsonConvert.DeserializeObject<List<OrderHeaderResult>>(orderData);
JsonConvert.DeserializeObject(orderData);

JsonConvert.DeserializeObject(orderData);

如何在Razor视图上显示列表?如何在Razor视图上显示列表?
JsonConvert.DeserializeObject<List<OrderHeaderResult>>(orderData);
JsonConvert.DeserializeObject<OrderHeaderResult>(orderData);