问题描述
我需要在远程服务器上提取一个json文件,在此保留文件的链接。 turkmedya.com.tr/anasayfa.json
我还分享了json文件的开放版本作为照片。enter image description here
Anasayfa.cs
public class data
{
public string sectionType { get; set; }
public string titleBgColor { get; set; }
public IList<veri> itemList { get; set; }
}
public class veri
{
public string shortText { get; set; }
public string fullPath { get; set; }
public string itemId { get; set; }
public string imageUrl { get; set; }
}
public class cat
{
public string categoryId { get; set; }
public string Title{ get; set; }
}
public class ListJson
{
public string errorMessage { get; set; }
public IList<data> data { get; set; }
public IList<cat> category { get; set; }
}
HomeController.cs
public ActionResult Index()
{
string url = @"http://turkmedya.com.tr/anasayfa.json";
string jsonVerisi = "";
try
{
using (WebClient response = new WebClient())
{
jsonVerisi = response.DownloadString(url);
}
ListJson account = JsonConvert.DeserializeObject<ListJson>(jsonVerisi);
foreach (var list in account.data)
{
System.Console.WriteLine(list.ToString());
ViewBag.ca = list.itemList.ToList();
var a = account.data.Count;
var b = list.itemList.Count;
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return View();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)