I’m creating json response in quite sophisticated framework and have problems with json escaping.
I’m able to grab char[] with text I’d like to escape. What’s the proper (and the best in case of performance) way to do escaping. Keep in mind that it’s not replacing character with character – it’s replacing (mostly) one character with two characters, so the array has to be rearranged.
Using common (Apache, Google, …) libraries would be appreciated.
edit:
Gson library looks fine for my purposes, however there’s a problem with snippet:
Gson gson2 = new Gson();
String json = gson2.toJson(new String(buf));
cause it encodes html as well. My task is to do just json encoding for given HTML markup, so I don’t want to have tags encoded like \u003e.
I alway use Gson from Google. It work fine for me and no escaping problems I meat ever. Try it.