【发布时间】:2021-02-19 19:57:33
【问题描述】:
我在一个 JSON URL 中有 8 个键/值对。我在一列中只有 4 条匹配的记录。我只需要在视图中显示 4 个匹配的记录。我创建了一个 dict 模型和其他列表模型。 ModelList Compare
根据屏幕截图,我需要 dict 中的第一个值,例如列表中的值,以便我能够在视图页面中填充 json 记录。
字典1:
public void GetList1Void()
{
string strAPIUrl = "https://raw.githubusercontent.com/wedeploy-examples/supermarket-web-example/master/products.json";
string jsonUrlProducts;
using (WebClient client = new WebClient())
{
jsonUrlProducts = client.DownloadString(strAPIUrl);
}
Dictionary<string, object> Jsondictresults = new Dictionary<string, object>();
var objResponseB = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(jsonUrlProducts);
foreach (Dictionary<string, object> DictMainKV in objResponseB)
{
foreach (KeyValuePair<string, object> item in DictMainKV)
{
Jsondictresults.Add(item.Key, item.Key);
}
break;
}
ViewBag.VBList1Void = Jsondictresults.Keys;
ViewData["VdataList1Void"] = Jsondictresults;
}
列表2:
public List<K360mapMaster> GetList2()
{
List<K360mapMaster> mappingListDb = new List<K360mapMaster>();
var query = from K360mapMaster in _context.K360mapMasters
select K360mapMaster;
var mappings = query.ToList();
foreach (var mappingData in mappings)
{
mappingListDb.Add(new K360mapMaster()
{
ClientCatalog = mappingData.ClientCatalog
});
}
return mappingListDb;
}
插入表格设计
【问题讨论】:
标签: c# asp.net-mvc linq .net-core asp.net-core-mvc