【常用工具类】解析工具类
2016-01-07 15:37
525 查看
public static String jsonEncode(Object object) { Gson gson = new Gson(); return gson.toJson(object); } public static Object jsonDecode(String jsonString, Type type) { if (jsonString == null) { return null; } Gson gson = new Gson(); Object object = null; try { object = gson.fromJson(jsonString, type); } catch (Exception e) { Util.log(e.getMessage()); e.printStackTrace(); } return object; } public static Map<Object, Object> jsonDecode(String jsonString) { if (jsonString == null) { return null; } Gson gson = new Gson(); Map<Object, Object> map = null; try { map = gson.fromJson(jsonString, new TypeToken<Map<Object, Object>>() { }.getType()); } catch (Exception e) { Util.log(e.getMessage()); } return map; } public static int parseInt(Object obj) { try { return (int) Double.parseDouble("" + obj); } catch (Exception e) { } return 0; } public static long parseLong(Object obj) { try { return (long) Double.parseDouble("" + obj); } catch (Exception e) { } return 0; } public static float parseFloat(Object obj) { try { return Float.parseFloat("" + obj); } catch (Exception e) { } return 0; }
相关文章推荐
- Python动态类型的学习---引用的理解
- 关于PHP浮点数你应该知道的(All 'bogus' about the float in PHP)
- Gson.toJson()时内存溢出StackOverflowError
- 土人系列AS入门教程 -- 对象篇
- C#托管堆对象实例包含内容分析
- C#实现获取不同对象中名称相同属性的方法
- javascript asp教程第十一课--Application 对象
- PowerShell中使用Out-String命令把对象转换成字符串输出的例子
- VBS教程:对象-正则表达式(RegExp)对象
- C#检查指定对象是否存在于ArrayList集合中的方法
- sql2008启动代理未将对象应用到实例解决方案
- C#编程自学之类和对象
- C++中对象的常引用、动态建立和释放相关知识讲解
- php中将一个对象保存到Session中的方法
- php对象和数组相互转换的方法
- PHP中把对象转换为关联数组代码分享
- C#写入对象或集合类型数据到xml文件的方法
- C#利用反射来判断对象是否包含某个属性的实现方法
- ASP.NET中使用Application对象实现简单在线人数统计功能
- asp提示Server 对象 错误 ASP 0178 : 80070005