ttvc_all
2017-05-24 13:07
采纳率: 50%
浏览 5.0k
已采纳

java上使用Gson转换长数字的字符串时,被当成了数字处理

直接上代码
public static void main(String[] args) {
String jsonString="{\"list\":[{\"Arrayname\": \"000292603088\",\"LUNID\": \"09FB\",\"Capacity\": \"134.8681640625\",\"UUID\": \"60000970000292603088533030394642\",\"Mode\": \"vmax\"},"
+ "{ \"Arrayname\": \"000292603088\",\"LUNID\":\"09EB\",\"Capacity\":\"134.8681640625\",\"UUID\": \"60000970000292603088533030394542\",\"Mode\":\"vmax\"}]}";
Gson gson = new Gson();

     Map<String, Object > itemmapMap=gson.fromJson(jsonString, Map.class);

        String tolist= itemmapMap.get("list").toString();
        System.out.println("原始信息:"+tolist);

    List<Map<String, Object>> listjson =gson.fromJson(tolist, List.class);
            for (int i = 0; i < listjson.size(); i++) {
                    Map<String, Object> itemMap=new HashMap<String, Object>();
                    itemMap=listjson.get(i);
                    Map<String, String> insertMap=new HashMap<String, String>();

                    insertMap.put("lunId", itemMap.get("UUID").toString());



                System.out.println("转换成了:"+insertMap.get("lunId"));
            }

}
原始信息:[{Arrayname=000292603088, LUNID=09FB, Capacity=134.8681640625, UUID=60000970000292603088533030394642, Mode=vmax}, {Arrayname=000292603088, LUNID=09EB, Capacity=134.8681640625, UUID=60000970000292603088533030394542, Mode=vmax}]

转换成了:6.00009700002926E31
转换成了:6.00009700002926E31

请大神指点,希望数据变成60000970000292603088533030394542,而不是6.00009700002926E31
请问gson是否能指定字段的转换类型

3条回答 默认 最新

相关推荐 更多相似问题