如何在c#中将字符串xml转换为json并在C#中通过SOAP发送

时间:2015-07-26 09:28:29

标签: c# asp.net json soap-client

如何将xml数据转换为JSON格式。我也希望通过SOAP发送它。

你能提供一些例子吗?

1 个答案:

答案 0 :(得分:8)

您可以使用JsonConvert类进行转换。

这是代码

 // To convert an XML node contained in string xml into a JSON string   
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    string jsonText = JsonConvert.SerializeXmlNode(doc);

    // To convert JSON text contained in string json into an XML node
    XmlDocument doc = JsonConvert.DeserializeXmlNode(json);

以上代码来自How to convert JSON to XML or XML to JSON?

通过soap Client to send SOAP request and received response

发送数据