I’m using the net.sf.json.JSONObject to create some data to be sent to a front end application, and the code I’m interacting with doesn’t like the ways its adding quotation marks to every field name.
For example:
myString = new JSONObject().put("JSON", "Hello, World!").toString();
produces the string {“JSON”: “Hello, World”}.
What I want it to return is {JSON: “Hello, World”} – without quotes around “JSON”. What do I have to do to make that happen?
The javadoc says
If you want to conform to the JSON syntax rules, you shouln’t remove the quotes.
Or if you don’t care about the rules, you could create you own simple method to contruct this strings.
Also, replace the 2 first occurrences of the quotes is valid, as @CharlesLeaf said.