为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
Cats萌萌 2023-09-16 20:07:39
我试图将此 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
查看完整描述

3 回答

?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

您可以在 Visual Studio 2015 中轻松完成,复制 json 数据并打开 Visual Studio 2015,单击编辑 ----> 选择性粘贴 ----> 将 JSON 粘贴为类

您可以对 xml 文件执行此操作。


查看完整回答
反对 回复 2023-09-16
?
红颜莎娜

TA贡献1842条经验 获得超12个赞

像这样创建模型。


  public class ShipmentAddress

{

    public int id { get; set; }

    public string firstName { get; set; }

    public string lastName { get; set; }

    public string address1 { get; set; }

    public string address2 { get; set; }

    public string city { get; set; }

    public int cityCode { get; set; }

    public string district { get; set; }

    public int districtId { get; set; }

    public string postalCode { get; set; }

    public string countryCode { get; set; }

    public string fullName { get; set; }

    public string fullAddress { get; set; }

}


public class InvoiceAddress

{

    public int id { get; set; }

    public string firstName { get; set; }

    public string lastName { get; set; }

    public string company { get; set; }

    public string address1 { get; set; }

    public string address2 { get; set; }

    public string city { get; set; }

    public string district { get; set; }

    public string postalCode { get; set; }

    public string countryCode { get; set; }

    public string fullName { get; set; }

    public string fullAddress { get; set; }

}


public class Line

{

    public int quantity { get; set; }

    public int productId { get; set; }

    public int salesCampaignId { get; set; }

    public string productSize { get; set; }

    public string merchantSku { get; set; }

    public string productName { get; set; }

    public int productCode { get; set; }

    public int merchantId { get; set; }

    public double price { get; set; }

    public string currencyCode { get; set; }

    public string productColor { get; set; }

    public int id { get; set; }

    public string sku { get; set; }

    public int vatBaseAmount { get; set; }

    public string barcode { get; set; }

    public string orderLineItemStatusName { get; set; }

}


public class PackageHistory

{

    public object createdDate { get; set; }

    public string status { get; set; }

}


public class Content

{

    public ShipmentAddress shipmentAddress { get; set; }

    public string orderNumber { get; set; }

    public double totalPrice { get; set; }

    public object taxNumber { get; set; }

    public InvoiceAddress invoiceAddress { get; set; }

    public string customerFirstName { get; set; }

    public string customerEmail { get; set; }

    public int customerId { get; set; }

    public string customerLastName { get; set; }

    public int id { get; set; }

    public long cargoTrackingNumber { get; set; }

    public string cargoTrackingLink { get; set; }

    public string cargoSenderNumber { get; set; }

    public List<Line> lines { get; set; }

    public long orderDate { get; set; }

    public string tcIdentityNumber { get; set; }

    public string currencyCode { get; set; }

    public List<PackageHistory> packageHistories { get; set; }

    public string shipmentPackageStatus { get; set; }

}


public class RootObject

{

    public int page { get; set; }

    public int size { get; set; }

    public int totalPages { get; set; }

    public int totalElements { get; set; }

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

}




查看完整回答
反对 回复 2023-09-16
?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

据我了解,您正在尝试根据 JSON 生成 C# 类。


在这里,我发布了一个完整的 C# 类,您可以使用它来绑定特定的 JSON。


public class ShipmentAddress

{

    public int id { get; set; }

    public string firstName { get; set; }

    public string lastName { get; set; }

    public string address1 { get; set; }

    public string address2 { get; set; }

    public string city { get; set; }

    public int cityCode { get; set; }

    public string district { get; set; }

    public int districtId { get; set; }

    public string postalCode { get; set; }

    public string countryCode { get; set; }

    public string fullName { get; set; }

    public string fullAddress { get; set; }

}


public class InvoiceAddress

{

    public int id { get; set; }

    public string firstName { get; set; }

    public string lastName { get; set; }

    public string company { get; set; }

    public string address1 { get; set; }

    public string address2 { get; set; }

    public string city { get; set; }

    public string district { get; set; }

    public string postalCode { get; set; }

    public string countryCode { get; set; }

    public string fullName { get; set; }

    public string fullAddress { get; set; }

}


public class Line

{

    public int quantity { get; set; }

    public int productId { get; set; }

    public int salesCampaignId { get; set; }

    public string productSize { get; set; }

    public string merchantSku { get; set; }

    public string productName { get; set; }

    public int productCode { get; set; }

    public int merchantId { get; set; }

    public double price { get; set; }

    public string currencyCode { get; set; }

    public string productColor { get; set; }

    public int id { get; set; }

    public string sku { get; set; }

    public int vatBaseAmount { get; set; }

    public string barcode { get; set; }

    public string orderLineItemStatusName { get; set; }

}


public class PackageHistory

{

    public object createdDate { get; set; }

    public string status { get; set; }

}


public class Content

{

    public ShipmentAddress shipmentAddress { get; set; }

    public string orderNumber { get; set; }

    public double totalPrice { get; set; }

    public object taxNumber { get; set; }

    public InvoiceAddress invoiceAddress { get; set; }

    public string customerFirstName { get; set; }

    public string customerEmail { get; set; }

    public int customerId { get; set; }

    public string customerLastName { get; set; }

    public int id { get; set; }

    public long cargoTrackingNumber { get; set; }

    public string cargoTrackingLink { get; set; }

    public string cargoSenderNumber { get; set; }

    public List<Line> lines { get; set; }

    public long orderDate { get; set; }

    public string tcIdentityNumber { get; set; }

    public string currencyCode { get; set; }

    public List<PackageHistory> packageHistories { get; set; }

    public string shipmentPackageStatus { get; set; }

}


public class RootObject

{

    public int page { get; set; }

    public int size { get; set; }

    public int totalPages { get; set; }

    public int totalElements { get; set; }

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

}

请检查它,如果您仍然面临共享类的问题,请告诉我。


查看完整回答
反对 回复 2023-09-16
  • 3 回答
  • 0 关注
  • 133 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信