I'm trying to use JsonBuilder in groovy servlet (extending HttpServlet) Here is a snippet:
public void doGet(HttpServletRequest request, HttpServletResponse response) {
response.setContentType('text/plain')
response.setCharacterEncoding('utf-8')
def pw = response.getWriter()
pw.println(new JsonBuilder(['city': 'Москва']))
pw.println([сity: 'Москва'])
}
The output is
{"city":"\u041C\u043E\u0441\u043A\u0432\u0430"}
{сity=Москва}
I just don't know nothing about UTF escaping in JsonBuilder, googling also did not give my anything valuable. So I guess I'm stuck.
Does anybody know how to get the output for json exactly in same form as we get the output for regular groovy object?
I have encountered the same issue, and the above methods didn't work. However this did: http://groovy.codehaus.org/gapi/groovy/json/StringEscapeUtils.html
StringEscapeUtils.unescapeJavaScript(JsonOutput.toJson('Москва'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With