【发布时间】:2019-10-02 16:14:55
【问题描述】:
这是我第一次在这里发帖,我已经尝试过搜索,但我找不到任何适合我的建议解决方案。
我正在尝试从 api 调用中获取 Json 响应并将其显示在 Web 网格视图中。目前我的网格只显示 json 的第一部分。见图片。我不确定是因为我的观点不正确还是因为我的反序列化。
我希望它在下面的响应 json 中显示运营商的每个费率:
[
{
"success": true,
"rate_response": [
{
"scac": "DAFG",
"service": "dayton_ltl",
"service_human": "代顿货运",
"carrier": "dayton",
"carrier_human": "代顿",
"estimated_transit_days": 1,
"cost": "$145.53"
},
{
"service": "FEDEX_EXPRESS_SAVER",
"service_human": "FedEx Express Saver",
"carrier": "fedex",
"carrier_human" : "Fedex Parcel",
"estimated_transit_days": 3,
"cost": "$179.78"
},
],
"rate_response_errors": [
{@9876545 "carrier": "BCP Transportation",
"message": "未检测到里程"
}
],
"pick_ticket_number": "99999",
"bol_number": "4861521889418148 "
}
]`
当前控制器
var result = JsonConvert.DeserializeObject<List<RootObject>>(jsonString);
return View("GridView", result);
ShipResponse 类:
public class RateResponse
{
[JsonProperty("scac")]
public string scac { get; set; }
[JsonProperty("service")]
public string service { get; set; }
[JsonProperty("service_human")]
public string service_human { get; set; }
[JsonProperty("carrier")]
public string carrier { get; set; }
[JsonProperty("carrier_human")]
public string carrier_human { get; set; }
[JsonProperty("estimated_transit_days")]
public int estimated_transit_days { get; set; }
[JsonProperty("cost")]
public string cost { get; set; }
}
public class RateResponseError
{
[JsonProperty("carrier")]
public string carrier { get; set; }
[JsonProperty("message")]
public string message { get; set; }
}
public class RootObject
{
[JsonProperty("success")]
public bool success { get; set; }
[JsonProperty("rate_response")]
public IList<RateResponse> rate_response { get; set; }
[JsonProperty("rate_response_errors")]
public IList<RateResponseError> rate_response_errors { get; set; }
[JsonProperty("pick_ticket_number")]
public string pick_ticket_number { get; set; }
}
}
GridView.cshtml:
@model List<P21.Rules.Visual.Areas.SwanleapQuote.Models.RootObject>
@{
ViewBag.Title = "GridView";
Layout = "~/Views/Shared/_VisualRuleLayout.cshtml";
}
<div>
<hr />
</div>
@foreach (var item in Model)
{
<div class="form-horizontal">
<form>
<h3>Rates</h3>
@{
var grid = new WebGrid(Model, canPage: true, canSort: true, rowsPerPage: 2);
grid.Pager(WebGridPagerModes.NextPrevious);
}
<div>
@grid.GetHtml(htmlAttributes: new
{
id = "grid",
@class = "table table-bordered table-striped table-condensed"
},
emptyRowCellValue: "No Records Found",
headerStyle: "grid-header")
</div>
<button class="btn btn-warning pull-right" type="submit">Return <i class="glyphicon glyphicon-arrow-right"></i></button>
</form>
</div>
我目前的结果只显示:
Success , rate_response , rate_response_errors , pick_ticket_number
我想让它给我看:
service_human、estimate_transit_days、成本
【问题讨论】:
-
我看不到代码、图片和 JSON。请将代码和数据以文本形式发布,not as pictures.
-
对不起,这是我第一次发帖。谢谢你的快速反应。我添加了一些代码和图片。
标签: c# asp.net-mvc model-view-controller model model-view