views:

317

answers:

1

I am serializing to a json object using:

public static string ToJson(this object obj)
{
    JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
    return jsonSerializer.Serialize(obj);
}

However when I'm populating a hidden field, I'm getting the slashes with it:

"[{\"ImageLink\":\"\",\"ShowOnHomePage\":null,\"Type\":\"AdListItem\",\"Key\":null,\"Title\":\"dsafdsaf\",\"Url\":\"fdsafdsa\",\"ContentSummary\":\"\u003cdiv\u003efdsafdsa\u003c/div\u003e\"},{\"ImageLink\":\"\",\"ShowOnHomePage\":null,\"Type\":\"AdListItem\",\"Key\":null,\"Title\":\"hddfg\",\"Url\":\"dsaf\",\"ContentSummary\":\"\u003cdiv\u003efdsafdsa\u003c/div\u003e\"},{\"ImageLink\":\"\",\"ShowOnHomePage\":null,\"Type\":\"AdListItem\",\"Key\":null,\"Title\":\"asfd\",\"Url\":\"asdf\",\"ContentSummary\":\"\u003cdiv\u003eafds\u003c/div\u003e\"}]"

How would I properly get rid of the \" and replace them with just " ???

Any Ideas?

Thanks.

+2  A: 

The slashes are Javascript string escape characters.

\" -> " so you can have a quote with-in a quote.

This is true for most all C-style languages (C, C++, C#, Java, etc)

Chris Brandsma