asp.net - 获取 json 文件时遇到的错误
问题描述
我需要在远程服务器上拉一个 json 文件。我把文件的链接留在这里。turkmedya.com.tr/anasayfa.json
我还将 json 文件的开放版本作为照片分享。在此处输入图像描述
我还必须从文件中提取类别。你能帮我个忙吗?
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();
}
解决方案
推荐阅读
- swift - TextEditor 键盘避免
- reactjs - 反应脚本无法识别?
- node.js - GAE:禁用已处理错误的错误报告
- javascript - 数据表数据未使用新的服务器数据更新
- in-app-purchase - 当用户在不使用应用内购买的情况下上传一定数量的创意产品图片时,是否有可能以某种方式收费
- python-3.x - RE:OpenCV、Python3 模块可以将 SPI 设备作为相机处理吗?
- kotlin - Kotlin:不兼容的类型:String 和 Int
- python - 在 juputerlab 上运行时 dask 在哪里存储文件
- javascript - 定义对象时的方括号是什么?
- go - 如何交叉编译转到 32 位 windows .exe