0

I have a this method to serialise objects to json.

public string SerialiseObject(object obj)
{
    using (var dataStream = new MemoryStream())
    using (var reader = new StreamReader(dataStream))
    {
        var objSer = new DataContractJsonSerializer(obj.GetType());
        objSer.WriteObject(dataStream, obj);
        dataStream.Position = 0;
        var bytes = Encoding.UTF8.GetBytes(reader.ReadToEnd());
        return Encoding.UTF8.GetString(bytes);
    }
}

It was working fine for all my objects unless I have this new property which holds a url in it.

MyObject.StoreUrl = "https://www.myCoffeeShop.com";

now when I use my serialize method it generates

"StoreUrl": "https:\/\/www.myCoffeeShop.com"

while I am expecting

"StoreUrl": "https://www.myCoffeeShop.com"

Can someone please tell me what am I missing?

Mohit S
  • 13,723
  • 6
  • 34
  • 69
ahsant
  • 1,003
  • 4
  • 17
  • 25
  • 1
    possible duplicate of [JSON: why are forward slashes escaped?](http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped) – aghidini Sep 14 '15 at 08:18
  • `HttpUtility.UrlEncode` – Oluwafemi Sep 14 '15 at 08:24
  • In the JSON standard, the forward slash character inside a string literal should be escaped in that way. See http://json.org/. – dbc Sep 14 '15 at 08:39

0 Answers0