【发布时间】:2012-10-26 04:13:01
【问题描述】:
我有一个 JSON 字符串:
var jsonString = JSON.stringify(dataObject);
document.getElementById("hdnChromedata").value = jsonString;
==> hdnChromedata = JSON 字符串
但在不同的代码部分中,我将 XML 序列化字符串存储到“hdnChromedata”.as :
XmlSerializer xmlSerializer = new XmlSerializer(vinDescription.GetType());
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, vinDescription);
this.hdnChromedata.Value = textWriter.ToString();
==> hdnChromedata = XML 字符串
在检索值时,我正在像这样反序列化字符串:
XmlDocument doc = new XmlDocument();
doc.LoadXml(this.hdnChromedata.Value);
XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
XmlSerializer ser = new XmlSerializer(decodedInfo.GetType());
object textObj = ser.Deserialize(reader);
vinDescription = (AutoExact.AEVINDecoderService.VINDescription)textObj;
这里是 doc.LoadXml(this.hdnChromedata.Value) 行 当 hdnChromedata 是 JSON 字符串时抛出错误。
我的问题是,如何将这个 JSON 字符串转换为 XML 字符串?
或者还有其他方法可以解决这个问题吗?
基本上我需要一种在 ASP.NET 1.1 中将 JSON 字符串转换为 XML 字符串的方法
【问题讨论】:
标签: c# asp.net json xml-serialization