json解析数据 1 public static T DataContractJsonDeSerializer(string jsonString) 2 { 3 var ds = new DataContractJsonSerializer(typeof(T)); 4 var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); 5 T obj = (T)ds.ReadObject(ms); 6 ms.Dispose(); 7 return obj; 8 } 9 10 public static string ToJsonData(object item)11 {12 DataContractJsonSerializer serializer = new DataContractJsonSerializer(item.GetType());13 string result = String.Empty;14 using (MemoryStream ms = new MemoryStream())15 {16 serializer.WriteObject(ms, item);17 ms.Position = 0;18 using (StreamReader reader = new StreamReader(ms))19 {20 result = reader.ReadToEnd();21 }22 }23 return result;24 }
xml解析数据
1 XmlDocument doc = new XmlDocument(); 2 doc.LoadXml(请求的数据); 3 XmlNodeList xmlNodeList = doc.SelectNodes("/root/data/info"); 4 //请求指定路径下面的节点 5 foreach (XmlElement node in xmlNodeList) 6 {下面在获取指定节点的数据 7 status.ID = node.SelectSingleNode("id").InnerText; 8 status.Text = node.SelectSingleNode("text").InnerText.ReplaceHtml(); 9 status.Source = node.SelectSingleNode("from").InnerText;10 }