Hi in my project i need to create a JSONArray type with the GSON class
{
\"message\": [
\"msg 1\",
\"msg 2\",
\"msg 3\"
],
\"asec\": [
Try below code to create JsonObject you desired.
String[] msgArray = new String[]{"msg 1", "msg 2", "msg 3"};
String[] asecArray = new String[]{"asec 1", "asec 2", "asec 3"};
Gson gson = new Gson();
JsonObject obj = new JsonObject(); //Json Object
obj.add("message", gson.toJsonTree(msgArray));
obj.add("asec", gson.toJsonTree(asecArray));
String jsonString = gson.toJson(obj); //Json String
Refer Gson documentation for more details