我在一个Api中有一个错误标记的json。现在我想在错误发生时在c#中显示错误内容。有没有人有这样的代码或例子?在C#中显示json错误标记#
--Edited--
string html = string.Empty;
string url = @"http://henn.worteus.eu/?tag=getdatas&token=21123&id=" + sessions;
WebRequest req = WebRequest.Create(url);
req.ContentType = "application/json";
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader re = new StreamReader(stream);
string json = re.ReadToEnd();
// Wrapper w = (Wrapper)new JavaScriptSerializer().Deserialize(json, typeof(Wrapper));
Wrapper w = (Wrapper)JsonConvert.DeserializeObject(json, typeof(Wrapper));
dataGrid.ItemsSource = w.data;
下面是数据模型
public class Data
{
public string Skala { get; set; }
public string Wert { get; set; }
public string Bereich { get; set; }
public string Interpretationen { get; set; }
}
public class Wrapper
{
public List<Data> data { get; set; }
public string tag { get; set; }
public object error { get; set; }
}
可能还想包含一些示例JSON。 – Lloyd
究竟是什么?问题中的代码与你的问题有什么关系? – Amy
“我想在c#中显示错误内容”是什么意思? – CodingYoshi