< groupId > com.google.code.gson </ groupId > < artifactId > gson </ artifactId > < version > 2.8.6 </ version > </ dependency >
  • 将数组转换为JSON字符串:
  • import com.google.gson.Gson;
    int[] arr = {1, 2, 3, 4, 5};
    Gson gson = new Gson();
    String json = gson.toJson(arr);
    

    现在,json字符串变量就是数组的JSON表示:[1, 2, 3, 4, 5]

  •