在XML和API用C#code错误信息 [英] Error message in XML and API with C# Code
本文介绍了在XML和API用C#code错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
href=\"http://stackoverflow.com/questions/30683402/c-sharp-$c$c-to-retrieve-xml-data\">support:
Based on this code below from previous support:
using (WebClient client = new WebClient())
{
client.Headers.Add("Accept-Language", " en-US");
client.Headers.Add("Accept", " text/html, application/xhtml+xml, */*");
client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
XDocument xml = XDocument.Parse(client.DownloadString("http://api.arbetsformedlingen.se/af/v0/platsannonser/matchning?lanid=1&kommunid=180&yrkesid=2419&1&antalrader=10000"));
}
我检索错误信息
{System.Xml.XmlException} {数据在根级别是无效的。行1,位置1。}
{System.Xml.XmlException} {"Data at the root level is invalid. Line 1, position 1."}
我试图解决它,但我无法找到一个解决的办法。
I tried solving it but I cannot find a solution to it.
推荐答案
您实际上得到一个JSON,更改以下内容:
You're actually getting a json, change the following:
client.Headers.Add("Accept", " text/html, application/xhtml+xml, */*");
到
client.Headers.Add("Accept", "application/xml");
这篇关于在XML和API用C#code错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文