tags:

views:

263

answers:

1

I'm using Gson to convert a Java object to Json. One of the object's fields holds a string containing an escaped double quote, like this:

"double quote:'\"'"

The toJson method returns the string as above, but I would like to print this instead:

double quote:'"'

Is this possible using Gson?

+1  A: 

Why would you want to do that? The surrounding quotes and the escape character are mandatory in JS/JSON as well.

The following JS piece just shows the correct value:

var json = { test: "double quote:'\"'" };
alert(json.test);

Don't print it using System.out.println() or so, Java doesn't parse JSON, only JS does that ;)

BalusC
I'm passing the JSON onto an Ext grid (via JSP) and it doesn't seem to like the escape characters.
ViralShah
Apparently you passed it the wrong way. E.g. `var foo = ${jsonFromServer};` should do (no quotes). If you're using JSTL `c:out`, ensure that its `escapeXml` attribute is set to `false`.
BalusC