xuechangchun007
EverSpring007
2017-12-04 08:51

httpclient获取返回的json串会自动转换成科学计数法

  • java
  • json
  • httpclient

在用httpclient获取返回的json数据时,有个值是5000000.0,在用EntityUtils.toString(entity, "utf-8");转换的时候会变成5.0E7,哪位知道怎么处理吗?

 String responseMsg = "";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpget = getHttpGet(url);

        try {
            httpget.setHeader("Content-Type", "application/xml; charset=utf-8");
            httpget.setHeader("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36");
            CloseableHttpResponse response = httpClient.execute(httpget);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    responseMsg = EntityUtils.toString(entity, "utf-8");
                }
            } finally {
                response.close();
            }
            httpClient.close();
        } catch (Exception e) {
            throw new SystemException("webservice请求异常", e);
        } finally {
            httpget.releaseConnection();
            httpClient.close();
            // httpClient.getConnectionManager().shutdown();
        }
        return responseMsg;

jdk自带的和OkHttp包也是同样返回

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答