import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.lang.reflect.Type;
/**
* json字符串与对象相互转换
*/
public class JsonHelp {
private static Gson gson = new GsonBuilder().create();
public static <T> T json2Bean(String jsonStr, Class<T> objClass){
return gson.fromJson(jsonStr, objClass);
}
public static <T> T json2Bean(String jsonStr, Type objClass){
return gson.fromJson(jsonStr, objClass);
}
public static String toJson(Object obj) {
String reString=gson.toJson(obj);
return reString;
}
}
Gson 字符串与对象相互转换工具类
最新推荐文章于 2022-08-03 10:25:31 发布