rnli rnli - 9 months ago 105
ASP.NET (C#) Question

Serialize string to JSON without \0027

A fairly straightforward question. I have the following code

var json = new JavaScriptSerializer();
var test = json.Serialize("'");

Now, Visual Studio local variable watch shows that
contains a string of value
. Is it possible, using build in ASP.NET to make
return serialized string without

The desired result for
would be


Answer Source

As the commenters mentioned, this really shouldn't matter because \u0027 literally represents a single quote in Javascript.

However, if this bothers you, you may want to try using JSON.NET, which leaves single-quotes in encoded strings as they are.