Hướng dẫn javascript escape special characters
Take your JSON and EDIT: As far as I know of, there are no well-known JS libraries for escaping all special characters in a string. But, you could chain the
But that's pretty nasty, isn't it? Enter the beauty of functions, in that they allow you to break code into pieces and keep the main
flow of your script clean, and free of 8 chained Like so:
Once we have defined that function, the main body of our code is as simple as this:
Table of Contents
In this post, we will see how to escape JSON string containing newline characters using JavaScript. There is no well known JavaScript library which can escape all special characters in String. There is no direct way to escape JSON String in JavaScript. You could however chain Here is one of way to do it.
You can create a custom function such as escapeSpecialCharsInJSONString() as below:
Let’s see with the help of example.
Output
As you can see, we have successfully escaped new line character and tab character from the JSON String. ConclusionTo escape JSON string containing newline characters, chain That’s all about how to escape JSON string containing newline characters in JavaScript. |