记录!!!! 记录!!!! 记录!!!!
Gson对含有纯数字的对象转换后可能出现类型问题,比如:
常用的转换方法:
String str = "[{key1=adddd, key2=1}]"; Gson gson = new Gson(); List<Map<String, String>> list = new ArrayList<>(); list = gson.fromJson(str,list.getClass());
返回值就变成了:[{key1=adddd, key2=1.0}]
解决办法:
String str = "[{key1=adddd, key2=1}]"; Gson gson = new Gson(); List<Map<String, String>> list = new ArrayList<>(); list = gson.fromJson(str,new TypeToken<List<Map<String, String>>>(){}.getType());