public class GsonUtil { /** * 将object对象转成json格式字符串 */ public static String toJson(Object object) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); return gson.toJson(object); } }
测试工具类,将使用谷歌的gson将object对象转成josn对象