Loading

C# 解析soap数据为json格式

数据格式:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:queryServiceResponse xmlns:ns2="http://impl.ws.remote.dataservice.apps.ut.comsys.net.cn/">
<return>
{
    "data": {
        "dwsjxx": [{
            "SFCX": "0",
            "SFST": "02444",
            "DWH": "2100",
            "LSDWH": "30000",
            "DWMC": "办公室",
            "DWJBSJZLB_ID": 0
        }, {
            "SFCX": "0",
            "SFST": "02444",
            "DWH": "2100",
            "LSDWH": "30000",
            "DWMC": "办公室1",
            "DWJBSJZLB_ID": 1
        }]
    },
    "success": true
}
</return>
</ns2:queryServiceResponse>
</soap:Body>
</soap:Envelope>

解析代码,得到return里面的数据:

            string Url = "http://############";


            X.Component.Tools.WebClient wc = new Component.Tools.WebClient();
            wc.Encoding = System.Text.Encoding.UTF8;
            var result = wc.GetHtml(Url);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(result);

            XmlElement root = doc.DocumentElement;

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");

            string value = doc.SelectSingleNode("//soap:Envelope", nsmgr).InnerText;

            X.Api.Department DepInfo = new X.Api.Department();
            JsonConvert.DeserializeObject<X.Api.Department>(value); //得到json数据

  

 

posted @ 2018-12-20 16:53  vanteking  阅读(3350)  评论(5编辑  收藏  举报