In this method, I have an array of strings i.e barchartLabels. I want to add this array to jsonObject:
Expected output is :
{ "data" : " [ "January", "February", "March", "April", "May", "June", "July" ] " }
public String array() {
JsonArray roleArray = new JsonArray();
String barChartLabels[] = {"January", "February", "March", "April", "May", "June", "July"};
Gson listG = new Gson();
JsonObject jsonObj = new JsonObject();
String list2 = listG.toJson(barChartLabels);
jsonObj.addProperty("data", list2);
roleArray.add(jsonObj);
return jsonObj.toString();
}
In the above method I'm using Gson object to convert barchartLabels to string then using jsonObject adding it. But I'm getting the output as shown below. Is there any other way to do the above mentioned?
{ "data" : " [ \"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\" ] " }
"so don't worry" "are being escaped. As @Pavneet_Singh has mentioned, this is completely standard.