0

Trying to escape special characters for json using following code

Dim testString As String = "this ""word"" is escaped"

Dim retruString = System.Text.RegularExpressions.Regex.Replace(testString, "\\([^""\\/bfnrtu])", "\\")

I know I have overlooked something really silly or maybe its been a long day/night, if anyone can point to my mistake would be greatly thankful

There is no error but the retruString is not escaped.

user1361914
  • 411
  • 1
  • 14
  • 26

1 Answers1

1

In .NET 4, you do not need a regex:

retruString = System.Web.HttpUtility.JavaScriptStringEncode(testString)

For older .NET versions, check out this post: How to escape JSON string?

Community
  • 1
  • 1
Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45