Javascript Escape from Json.Net

The Json.NET homepage says the project started as:

some static methods for escaping javascript strings

Are these methods persisted? I know that JavaScriptSerializer can do this, but I have to make one liner for this.

SerializeObject can serialize a single line (which escapes from it), but returns quotation marks

 JsonConvert.SerializeObject(@"hi bud \no way\"); 

Returns: "hi bud \\no way\\"

+4
source share
1 answer

I found a nice one-line solution, but it was only in scope with 4.0. It would be nice to have something like this in Json.NET that I can use on <4.0.

HttpUtility.JavaScriptStringEncode example:

 HttpUtility.JavaScriptStringEncode(@"hi bud \no way\") 

Returns: hi bud\u0027s \\no way\\

+6
source

Source: https://habr.com/ru/post/1435409/


All Articles