.NET 3.5支持读取JSON格式的数据。只要
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
就可以。这两个命名空间,要添加引用:System.Runtime.Serialization
。
读取到XML
HttpWebResponse response = 根据页面地址抓取到的该页面内容,全部是JSON数据。
Stream stream = response.GetResponseStream();
XmlDictionaryReader xmlReader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max);
xmlReader.Read();
String XMLString = xmlReader.ReadOuterXml();
stream.Close();
stream.Dispose();
XmlDataDocument doc = new XmlDataDocument();
doc.DataSet.ReadXmlSchema(“json.xsd”);//这个XSD是针对JSON格式写的一个格式文件
doc.LoadXml(XMLString);
DataSet ds = doc.DataSet;//获取到数据。
主要是这个XSD该怎么写。
本文介绍如何使用.NET3.5读取JSON格式数据,并将其转换为XML格式以便进一步处理。通过使用System.Runtime.Serialization命名空间中的相关类,可以实现从HTTP响应中读取JSON数据,并将其解析成XML,最终加载到DataSet中。
2687

被折叠的 条评论
为什么被折叠?



