【发布时间】:2017-07-27 17:39:14
【问题描述】:
我正在尝试将从 Web API 检索到的 Json 对象反序列化为强类型对象列表,如下所示:
WebClient wc = new WebClient();
// Downloading & Deserializing the Json file
var jsonMain = wc.DownloadString("http://api.flexianalysis.com/services/FlexiAnalysisService.svc/FlexiAnalysisNews?key=___&catagory=Forex");
JObject token2 = JObject.Parse(jsonMain);
List<News> listNews = new List<News>();
foreach (var result in token2["d"])
{
news = new News();
news.id = (string)result["ID"];
news.Title = (string)result["Title"];
news.Date = (string)result["PublishingDate"];
news.Content = (string)result["News"];
listNews.Add(news);
}
return View(listNews);
问题是我总是得到 1 个字符串的结果,因为解析器没有解析一个有效的 Json 对象。 (我猜它是无效字符,无法正确解析)...
有人有什么想法吗?
【问题讨论】:
-
那么你想要一个 JSON 解析器来解析非 JSON 吗?
-
d的内容是一个有效的 JSON。我刚刚在jsonviewer.stack.hu 中将其可视化
标签: c# .net json api deserialization