用list<类>集合接收一个网址返回的一个类的集合的XML

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string json = Share.Helper.HttpRequest("http://api.veggieg.com/article?order&type=focus");//把传过来的XML转换成Json格式

            List<Student> = serializer.Deserialize<List<Student>>(json);//把json格式解析成类
        //读取URL返回的内容,并返回JSON格式(在线)
public static string HttpRequest(string url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string str = reader.ReadToEnd(); reader.Close(); return str; }
 
   
 
  
            把本地的XML文件转成Json格式(本地)

            string xmlFile = Server.MapPath(@"Gen.xml");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(xmlFile);

            string jsonText = JsonConvert.SerializeXmlNode(xmlDoc);
            把本地的XML文件转成string类型(本地)

            string xmlFile = Server.MapPath(@"Gen.xml");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(xmlFile);

            string xmlStr = xmlDoc.OuterXml;

 

你可能感兴趣的:(list)