Json.Net を使用して XML 文字列を Json に変換しようとしています
Json.Netドキュメントでは、このコードを使用して xml を json に変換する必要があると書かれています。
string xml = @"<person id='1'>
<name>Alan</name>
<url>http://www.google.com</url>
<role>Admin1</role>
</person>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string json = JsonConvert.SerializeXmlNode(doc);
しかし、私の Windows 8 アプリでは、XmlDocument クラスも SerializeXmlNode も見つかりません。
これらのクラスと関数で試しました:
var result = await response.Content.ReadAsStringAsync();
XDocument xdoc = new XDocument();
xdoc = XDocument.Load(result);
// Parse the JSON Radio data
string jsonText = JsonConvert.SerializeXNode(xdoc);
var radios = JsonArray.Parse(result);
しかし、次のエラーが表示されます。
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
Additional information: Illegal characters in path.
If there is a handler for this exception, the program may be safely continued.
その結果、正しいxmlがロードされました。で始まります:
<?xml version="1.0" encoding="utf-8"?>
<item>...</item>