C# json字符串转为对象
方法一
- using System.Web.Script.Serialization;
- string ss = "{\"NewsCount\":\"3482\",\"NewsList\":[{\"Title\":\"成都建国“牵手起亚、爱心互助”成功举行\",\"Content\":\"...感恩而永恒5月16日建国起亚k系车友会开展“牵手起亚爱心互助...在这项活动中我们建国起亚k系车友会启动了阳光关爱工程为每个学生准备了生活学习必需品同时建国起亚...\",\"Path\":\"http://news.bitauto.com/dealer/20120521/1305698858.html\",\"PublishTime\":\"5/21/2012 1:40:00 PM\"}]}";
- JavaScriptSerializer js = new JavaScriptSerializer();
- SearchNews sn =js.Deserialize<SearchNews>(ss);
方法二
- using System.Runtime.Serialization.Json;
- using System.IO;
- string ss = "{\"NewsCount\":\"3482\",\"NewsList\":[{\"Title\":\"成都建国“牵手起亚、爱心互助”成功举行\",\"Content\":\"...感恩而永恒5月16日建国起亚k系车友会开展“牵手起亚爱心互助...在这项活动中我们建国起亚k系车友会启动了阳光关爱工程为每个学生准备了生活学习必需品同时建国起亚...\",\"Path\":\"http://news.bitauto.com/dealer/20120521/1305698858.html\",\"PublishTime\":\"5/21/2012 1:40:00 PM\"}]}";
- var ser = new DataContractJsonSerializer(typeof(SearchNews));
- var ms = new MemoryStream(Encoding.UTF8.GetBytes(ss));
- SearchNews sn= (SearchNews)ser.ReadObject(ms);