亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 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條經驗 獲得超13個贊

像這樣創建模型。


  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 關注
  • 186 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號