bean和json相互转换的工具(基于谷歌的gson)
2016-01-28 00:00
741 查看
摘要: 转换的工具
package com.panda.change.util; import java.lang.reflect.Type; import com.google.gson.Gson; /** * java对象和Json字符串转化工具类 * @author think */ public final class JsonUtil { private JsonUtil() { } /** * 对象转化成json字符串 * @param obj * @return */ public static String toJson(Object obj){ Gson gson = new Gson(); return gson.toJson(obj); } /** * json字符串转成对象 * @param str * @param type * @return */ public static <T> T fromJson(String str,Type type){ Gson gson = new Gson(); return gson.fromJson(str, type); } /** * json字符串转成对象 * @param str * @param type * @return */ public static <T> T fromJson(String str, Class<T> type) { Gson gson = new Gson(); return gson.fromJson(str, type); } }
相关文章推荐
- XML 与 JSON 优劣对比
- VBA将excel数据表生成JSON文件
- newtonsoft.json解析天气数据出错解决方法
- vbs 解析json jsonp的方法
- Extjs4如何处理后台json数据中日期和时间
- C#实现将类的内容写成JSON格式字符串的方法
- JQuery ajax返回JSON时的处理方式 (三种方式)
- jquery JSON的解析方式示例介绍
- c#版json数据解析示例分享
- ASP JSON类文件的使用方法
- C#实现对Json字符串处理实例
- C#实现Json转Unicode的方法
- php解析json数据实例
- PHP中JSON的应用技巧
- PHP6 先修班 JSON实例代码
- 关于JSON以及JSON在PHP中的应用技巧
- .Net中的json操作类用法分析
- C#操作 JSON方法汇总
- JavaScript中字符串(string)转json的2种方法
- js Object2String方便查看js对象内容