MrT*_*uch 1 c# xml json json.net windows-runtime
我尝试用Json.Net将我的XML String转换为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);
Run Code Online (Sandbox Code Playgroud)
但在我的Windows 8 App中,我找不到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);
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
结果我加载了正确的xml.从...开始:
<?xml version="1.0" encoding="utf-8"?>
<item>...</item>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3348 次 |
| 最近记录: |