写出小testcase
object Test { def main(args: Array[String]): Unit = { val tmpArrayList = new util.ArrayList[JSONObject]() val tmpMap = new JSONObject(true) tmpMap.put("id",1) tmpMap.put("name","hello") tmpArrayList.add(tmpMap) print(JSON.toJSONString(tmpArrayList,true)) } }打印结果
[ { "id":1, "name":"hello" } ]然后JSON.toJSONString(tmpArrayList,true)改成false
object Test { def main(args: Array[String]): Unit = { val tmpArrayList = new util.ArrayList[JSONObject]() val tmpMap = new JSONObject(true) tmpMap.put("id",1) tmpMap.put("name","hello") tmpArrayList.add(tmpMap) print(JSON.toJSONString(tmpArrayList,false)) } }打印结果
[{"id":1,"name":"hello"}]所以解决方案: JSON.toJSONString(tmpArrayList,true)改成false