1,对象转为 Gson 字符串
public static String objectToJsonString(Object object) {
Gson gson = new Gson();
return gson.toJson(object);
}
2,Gson字符串转为对象
public static <T> T jsonStringToObject(String string, Class<T> T) {
Gson gson = new Gson();
return gson.fromJson(string, T);
}
3,Gson字符串转为List对象集合
Gson gson = new Gson();
List<IndexStocksQuotes> listStockInfos = gson.fromJson(jsonString, new TypeToken<ArrayList<IndexStocksQuotes>>() {
}.getType());