如何在 mvc 中列出此 json 数据?

我试图将此 json 数据列为 mvc。如何编写视图模型代码?我已经编写了 json 数据和 viewmodel 编码。


查看型号:


public class OrderViewModel

{

    public List<Content> content { get; set; }

}



public class Content

{

    public string shipmentAddress { get; set; }

    public string firstName { get; set; }

    public string  lastName { get; set; }

    public string address1 { get; set; }

}

这个错误

读取字符串时出错。意外标记:StartObject。路径“ content[0].shipmentAddress”,第 1 行,位置 90


Cats萌萌
浏览 134回答 3
3回答

陪伴而非守候

您可以在 Visual Studio 2015 中轻松完成,复制 json 数据并打开 Visual Studio 2015,单击编辑 ----> 选择性粘贴 ----> 将 JSON 粘贴为类您可以对 xml 文件执行此操作。

红颜莎娜

像这样创建模型。&nbsp; public class ShipmentAddress{&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string firstName { get; set; }&nbsp; &nbsp; public string lastName { get; set; }&nbsp; &nbsp; public string address1 { get; set; }&nbsp; &nbsp; public string address2 { get; set; }&nbsp; &nbsp; public string city { get; set; }&nbsp; &nbsp; public int cityCode { get; set; }&nbsp; &nbsp; public string district { get; set; }&nbsp; &nbsp; public int districtId { get; set; }&nbsp; &nbsp; public string postalCode { get; set; }&nbsp; &nbsp; public string countryCode { get; set; }&nbsp; &nbsp; public string fullName { get; set; }&nbsp; &nbsp; public string fullAddress { get; set; }}public class InvoiceAddress{&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string firstName { get; set; }&nbsp; &nbsp; public string lastName { get; set; }&nbsp; &nbsp; public string company { get; set; }&nbsp; &nbsp; public string address1 { get; set; }&nbsp; &nbsp; public string address2 { get; set; }&nbsp; &nbsp; public string city { get; set; }&nbsp; &nbsp; public string district { get; set; }&nbsp; &nbsp; public string postalCode { get; set; }&nbsp; &nbsp; public string countryCode { get; set; }&nbsp; &nbsp; public string fullName { get; set; }&nbsp; &nbsp; public string fullAddress { get; set; }}public class Line{&nbsp; &nbsp; public int quantity { get; set; }&nbsp; &nbsp; public int productId { get; set; }&nbsp; &nbsp; public int salesCampaignId { get; set; }&nbsp; &nbsp; public string productSize { get; set; }&nbsp; &nbsp; public string merchantSku { get; set; }&nbsp; &nbsp; public string productName { get; set; }&nbsp; &nbsp; public int productCode { get; set; }&nbsp; &nbsp; public int merchantId { get; set; }&nbsp; &nbsp; public double price { get; set; }&nbsp; &nbsp; public string currencyCode { get; set; }&nbsp; &nbsp; public string productColor { get; set; }&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string sku { get; set; }&nbsp; &nbsp; public int vatBaseAmount { get; set; }&nbsp; &nbsp; public string barcode { get; set; }&nbsp; &nbsp; public string orderLineItemStatusName { get; set; }}public class PackageHistory{&nbsp; &nbsp; public object createdDate { get; set; }&nbsp; &nbsp; public string status { get; set; }}public class Content{&nbsp; &nbsp; public ShipmentAddress shipmentAddress { get; set; }&nbsp; &nbsp; public string orderNumber { get; set; }&nbsp; &nbsp; public double totalPrice { get; set; }&nbsp; &nbsp; public object taxNumber { get; set; }&nbsp; &nbsp; public InvoiceAddress invoiceAddress { get; set; }&nbsp; &nbsp; public string customerFirstName { get; set; }&nbsp; &nbsp; public string customerEmail { get; set; }&nbsp; &nbsp; public int customerId { get; set; }&nbsp; &nbsp; public string customerLastName { get; set; }&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public long cargoTrackingNumber { get; set; }&nbsp; &nbsp; public string cargoTrackingLink { get; set; }&nbsp; &nbsp; public string cargoSenderNumber { get; set; }&nbsp; &nbsp; public List<Line> lines { get; set; }&nbsp; &nbsp; public long orderDate { get; set; }&nbsp; &nbsp; public string tcIdentityNumber { get; set; }&nbsp; &nbsp; public string currencyCode { get; set; }&nbsp; &nbsp; public List<PackageHistory> packageHistories { get; set; }&nbsp; &nbsp; public string shipmentPackageStatus { get; set; }}public class RootObject{&nbsp; &nbsp; public int page { get; set; }&nbsp; &nbsp; public int size { get; set; }&nbsp; &nbsp; public int totalPages { get; set; }&nbsp; &nbsp; public int totalElements { get; set; }&nbsp; &nbsp; public List<Content> content { get; set; }}

人到中年有点甜

据我了解,您正在尝试根据 JSON 生成 C# 类。在这里,我发布了一个完整的 C# 类,您可以使用它来绑定特定的 JSON。public class ShipmentAddress{&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string firstName { get; set; }&nbsp; &nbsp; public string lastName { get; set; }&nbsp; &nbsp; public string address1 { get; set; }&nbsp; &nbsp; public string address2 { get; set; }&nbsp; &nbsp; public string city { get; set; }&nbsp; &nbsp; public int cityCode { get; set; }&nbsp; &nbsp; public string district { get; set; }&nbsp; &nbsp; public int districtId { get; set; }&nbsp; &nbsp; public string postalCode { get; set; }&nbsp; &nbsp; public string countryCode { get; set; }&nbsp; &nbsp; public string fullName { get; set; }&nbsp; &nbsp; public string fullAddress { get; set; }}public class InvoiceAddress{&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string firstName { get; set; }&nbsp; &nbsp; public string lastName { get; set; }&nbsp; &nbsp; public string company { get; set; }&nbsp; &nbsp; public string address1 { get; set; }&nbsp; &nbsp; public string address2 { get; set; }&nbsp; &nbsp; public string city { get; set; }&nbsp; &nbsp; public string district { get; set; }&nbsp; &nbsp; public string postalCode { get; set; }&nbsp; &nbsp; public string countryCode { get; set; }&nbsp; &nbsp; public string fullName { get; set; }&nbsp; &nbsp; public string fullAddress { get; set; }}public class Line{&nbsp; &nbsp; public int quantity { get; set; }&nbsp; &nbsp; public int productId { get; set; }&nbsp; &nbsp; public int salesCampaignId { get; set; }&nbsp; &nbsp; public string productSize { get; set; }&nbsp; &nbsp; public string merchantSku { get; set; }&nbsp; &nbsp; public string productName { get; set; }&nbsp; &nbsp; public int productCode { get; set; }&nbsp; &nbsp; public int merchantId { get; set; }&nbsp; &nbsp; public double price { get; set; }&nbsp; &nbsp; public string currencyCode { get; set; }&nbsp; &nbsp; public string productColor { get; set; }&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public string sku { get; set; }&nbsp; &nbsp; public int vatBaseAmount { get; set; }&nbsp; &nbsp; public string barcode { get; set; }&nbsp; &nbsp; public string orderLineItemStatusName { get; set; }}public class PackageHistory{&nbsp; &nbsp; public object createdDate { get; set; }&nbsp; &nbsp; public string status { get; set; }}public class Content{&nbsp; &nbsp; public ShipmentAddress shipmentAddress { get; set; }&nbsp; &nbsp; public string orderNumber { get; set; }&nbsp; &nbsp; public double totalPrice { get; set; }&nbsp; &nbsp; public object taxNumber { get; set; }&nbsp; &nbsp; public InvoiceAddress invoiceAddress { get; set; }&nbsp; &nbsp; public string customerFirstName { get; set; }&nbsp; &nbsp; public string customerEmail { get; set; }&nbsp; &nbsp; public int customerId { get; set; }&nbsp; &nbsp; public string customerLastName { get; set; }&nbsp; &nbsp; public int id { get; set; }&nbsp; &nbsp; public long cargoTrackingNumber { get; set; }&nbsp; &nbsp; public string cargoTrackingLink { get; set; }&nbsp; &nbsp; public string cargoSenderNumber { get; set; }&nbsp; &nbsp; public List<Line> lines { get; set; }&nbsp; &nbsp; public long orderDate { get; set; }&nbsp; &nbsp; public string tcIdentityNumber { get; set; }&nbsp; &nbsp; public string currencyCode { get; set; }&nbsp; &nbsp; public List<PackageHistory> packageHistories { get; set; }&nbsp; &nbsp; public string shipmentPackageStatus { get; set; }}public class RootObject{&nbsp; &nbsp; public int page { get; set; }&nbsp; &nbsp; public int size { get; set; }&nbsp; &nbsp; public int totalPages { get; set; }&nbsp; &nbsp; public int totalElements { get; set; }&nbsp; &nbsp; public List<Content> content { get; set; }}请检查它,如果您仍然面临共享类的问题,请告诉我。
打开App,查看更多内容
随时随地看视频慕课网APP