Below is my method, which does JSONObjectand then prints JSONString.
I am using Google GSON.
private String generateData(ConcurrentMap<String, Map<Integer, Set<Integer>>> dataTable, int i) {
JsonObject jsonObject = new JsonObject();
Set<Integer> ap = dataTable.get("TEST1").get(i);
Set<Integer> bp = dataTable.get("TEST2").get(i);
jsonObject.addProperty("description", "test data");
jsonObject.addProperty("ap", ap.toString());
jsonObject.addProperty("bp", bp.toString());
System.out.println(jsonObject.toString());
return jsonObject.toString();
}
Currently, if I print jsonObject.toString(), then it prints like this -
{"description":"test data","ap":"[0, 1100, 4, 1096]","bp":"[1101, 3, 6, 1098]"}
But that is not what I need. I want to print, as shown below, without double quotes in the apand values bp.
{"description":"test data","ap":[0, 1100, 4, 1096],"bp":[1101, 3, 6, 1098]}
I'm not sure how to avoid these quotes in a JSONObject?
user2467545
source
share