JSONObject put List<Double> 后转化为String问题的解决办法

//原代码
 JSONObject powerCurveJsonObj = new JSONObject();

  powerCurveJsonObj.put("test",[0.5, 1.0, 1.5]); //后面是 List<Double>

这种方法存储的 List<Double>会变成一个string类型,返回的时候会再Double列表上面加引号"[0.5, 1.0, 1.5]"


解决办法:

将JSONObject中需要存储的数据存放到Map中

Map<String, Object> map = new HashMap<>();

map.put("test",[0.5, 1.0, 1.5]);

JSONObject powerCurveJsonObj = new JSONObject(map);


将map转化为JSONObject类型就可以解决此类问题

  

原文地址:https://www.cnblogs.com/ilazysoft/p/6647179.html