java中使用json传递数据,丢失精度了,求各位大神指点一二一下如何解决json精度问题
rainWaterServicers=newrainWaterServiceImpl();List<rainwater>rr=newArrayList<rainwater...
rainWaterService rs=new rainWaterServiceImpl();
List<rainwater> rr=new ArrayList<rainwater>();
rr=(List<rainwater>) rs.getList();
for (int i = 0; i < rr.size(); i++) {
rainwater rw=rr.get(i);
System.out.println("日期:"+rw.getDt().trim()+"月 蒸发量:"+rw.getEvaporate()+" 降雨量:"+rw.getRainfall());
}
JSONArray jsonarray=JSONArray.fromObject(rs.getList());//=JSONArray.
request.setAttribute("data", jsonarray);
System.out.println(jsonarray);
日期:1月 蒸发量:2.0 降雨量:2.6
日期:10月 蒸发量:6.4 降雨量:6.0
日期:11月 蒸发量:3.3 降雨量:2.3
日期:12月 蒸发量:1.2 降雨量:2.0
日期:2月 蒸发量:4.9 降雨量:5.9
日期:3月 蒸发量:23.2 降雨量:9.0
日期:4月 蒸发量:25.6 降雨量:26.4
日期:5月 蒸发量:76.7 降雨量:28.7
日期:6月 蒸发量:135.6 降雨量:70.7
日期:7月 蒸发量:162.2 降雨量:175.6
日期:8月 蒸发量:32.6 降雨量:48.7
日期:9月 蒸发量:20.0 降雨量:18.8
[{"dt":"1 ","evaporate":2,"rainfall":2.5999999046325684},{"dt":"10 ","evaporate":6.400000095367432,"rainfall":6},{"dt":"11 ","evaporate":3.299999952316284,"rainfall":2.299999952316284},{"dt":"12 ","evaporate":1.2000000476837158,"rainfall":2},{"dt":"2 ","evaporate":4.900000095367432,"rainfall":5.900000095367432},{"dt":"3 ","evaporate":23.200000762939453,"rainfall":9},{"dt":"4 ","evaporate":25.600000381469727,"rainfall":26.399999618530273},{"dt":"5 ","evaporate":76.69999694824219,"rainfall":28.700000762939453},{"dt":"6 ","evaporate":135.60000610351562,"rainfall":70.69999694824219},{"dt":"7 ","evaporate":162.1999969482422,"rainfall":175.60000610351562},{"dt":"8 ","evaporate":32.599998474121094,"rainfall":48.70000076293945},{"dt":"9 ","evaporate":20,"rainfall":18.799999237060547}] 展开
List<rainwater> rr=new ArrayList<rainwater>();
rr=(List<rainwater>) rs.getList();
for (int i = 0; i < rr.size(); i++) {
rainwater rw=rr.get(i);
System.out.println("日期:"+rw.getDt().trim()+"月 蒸发量:"+rw.getEvaporate()+" 降雨量:"+rw.getRainfall());
}
JSONArray jsonarray=JSONArray.fromObject(rs.getList());//=JSONArray.
request.setAttribute("data", jsonarray);
System.out.println(jsonarray);
日期:1月 蒸发量:2.0 降雨量:2.6
日期:10月 蒸发量:6.4 降雨量:6.0
日期:11月 蒸发量:3.3 降雨量:2.3
日期:12月 蒸发量:1.2 降雨量:2.0
日期:2月 蒸发量:4.9 降雨量:5.9
日期:3月 蒸发量:23.2 降雨量:9.0
日期:4月 蒸发量:25.6 降雨量:26.4
日期:5月 蒸发量:76.7 降雨量:28.7
日期:6月 蒸发量:135.6 降雨量:70.7
日期:7月 蒸发量:162.2 降雨量:175.6
日期:8月 蒸发量:32.6 降雨量:48.7
日期:9月 蒸发量:20.0 降雨量:18.8
[{"dt":"1 ","evaporate":2,"rainfall":2.5999999046325684},{"dt":"10 ","evaporate":6.400000095367432,"rainfall":6},{"dt":"11 ","evaporate":3.299999952316284,"rainfall":2.299999952316284},{"dt":"12 ","evaporate":1.2000000476837158,"rainfall":2},{"dt":"2 ","evaporate":4.900000095367432,"rainfall":5.900000095367432},{"dt":"3 ","evaporate":23.200000762939453,"rainfall":9},{"dt":"4 ","evaporate":25.600000381469727,"rainfall":26.399999618530273},{"dt":"5 ","evaporate":76.69999694824219,"rainfall":28.700000762939453},{"dt":"6 ","evaporate":135.60000610351562,"rainfall":70.69999694824219},{"dt":"7 ","evaporate":162.1999969482422,"rainfall":175.60000610351562},{"dt":"8 ","evaporate":32.599998474121094,"rainfall":48.70000076293945},{"dt":"9 ","evaporate":20,"rainfall":18.799999237060547}] 展开
1个回答
2015-07-02
展开全部
把你传的数值类型数据转成字符串再传递就行了
现在是
{"dt":"1 ","evaporate":2,"rainfall":2.5999999046325684}
改成
{"dt":"1 ","evaporate":2,"rainfall":"2.5999999046325684"}
如果类rainwater是你自己定义的,就比较简单了,吧Rainfall属性的类型从double改成String
如果不是就只能在数据转json前先遍历整个集合,然后转字段类型了
现在是
{"dt":"1 ","evaporate":2,"rainfall":2.5999999046325684}
改成
{"dt":"1 ","evaporate":2,"rainfall":"2.5999999046325684"}
如果类rainwater是你自己定义的,就比较简单了,吧Rainfall属性的类型从double改成String
如果不是就只能在数据转json前先遍历整个集合,然后转字段类型了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询