`
yangshen998
  • 浏览: 1248944 次
文章分类
社区版块
存档分类
最新评论

.NET 读取 JSON格式的数据

 
阅读更多


.NET 3.5支持读取JSON格式的数据。只要
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

就可以。这两个命名空间,要添加引用:System.Runtime.Serialization

只引用一个System.Runtime.Serialization 是不够的,

还要添加 System.ServiceModel

System.ServiceModel.Web

的引用

读取到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该怎么写。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics