I have written a webservice which converts the XML Response of a TP-Open Service into JSON format. I am new to WCF and writing Webservice. But the converted JSON format displays as follow.
"{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"25\", \"humidity\": \"48\", \"observation_time..
How to Remove these back slashes \ and my code so far.
   public string checkweather(string q, string num_of_day)
    {
         HttpWebRequest request=..;
               ...
        string Url = string.Format("http://free.worldweatheronline.com/feed/weather.ashx?q={0}&format={1}&num_of_days={2}&key={3}", q, format, num_of_days, key);
        HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Url);
        Request.Method = "GET";
        using (HttpWebResponse response = (HttpWebResponse)Request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    var result2=reader.ReadToEnd();
         }}}
          return result2;
         }
Please inform me if you need more information.
I think that your JSON is fine, the backslashes are escaping the quotations, which people have said. The following code shows some valid XML -> Json converting. (Using Json.NET)
const string xml = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
XmlDocument node = new XmlDocument();
node.LoadXml(xml);
string json = JsonConvert.SerializeXmlNode(node);
If you view in debug mode, you will see the backslashes, but the output is valid Json.
Output
{"note":{"to":"Tove","from":"Jani","heading":"Reminder","body":"Don't forget me this weekend!"}}
                        Are you sure there are backslashes in your string? It looks like me they are the escape characters because there are " characters in your string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With