标签:create json util token tool list ring dem hang
1:GsonTools.java
package com.example.c10demo; import java.util.List; import java.util.Map; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class GsonTools { public GsonTools() { // TODO Auto-generated constructor stub } public static String createGsonString(Object object) { Gson gson = new Gson(); String gsonString = gson.toJson(object); return gsonString; } public static <T> T changeGsonToBean(String gsonString, Class<T> cls) { Gson gson = new Gson(); T t = gson.fromJson(gsonString, cls); return t; } public static <T> List<T> changeGsonToList(String gsonString, Class<T> cls) { Gson gson = new Gson(); List<T> list = gson.fromJson(gsonString, new TypeToken<List<T>>() { }.getType()); return list; } public static <T> List<Map<String, T>> changeGsonToListMaps( String gsonString) { List<Map<String, T>> list = null; Gson gson = new Gson(); list = gson.fromJson(gsonString, new TypeToken<List<Map<String, T>>>() { }.getType()); return list; } public static <T> Map<String, T> changeGsonToMaps(String gsonString) { Map<String, T> map = null; Gson gson = new Gson(); map = gson.fromJson(gsonString, new TypeToken<Map<String, T>>() { }.getType()); return map; } }
标签:create json util token tool list ring dem hang
原文地址:http://www.cnblogs.com/wnpp/p/7865875.html