Im using the JavaScriptSerializer Class to serilize and Deserilize in/to Json.
I know there is a json.net library out there.
But My question is :
Can I also use JavaScriptSerializer class to escape my json string ?
or should I do it myself ? and if so should I do it by encodeURIComponent ?
Yes, it’s an appropriate way to safely encode a string. Just call serialize on your string.
To be more clear, if you look into the actual JavaScriptSerializer implementation (I’m using dotpeek), you can see that it actually calls this function:
So I guess another answer is that you can just use
HttpUtility.JavaScriptStringEncode, although it won’t add the double quotes around it.